FIXUP: WIP: verification_trailer
[wireshark-wip.git] / epan / dissectors / packet-mplstp-oam.c
blob4e329570cd1867f16c6ce45ff4e4ef8295fffcda
1 /* packet-mplstp-oam.c
3 * $Id$
4 * Routines for MPLS-TP Lock Instruct Protocol : RFC 6435
5 * MPLS-TP Fault-Management Protocol : RFC 6427
7 * Authors:
8 * Krishnamurthy Mayya <krishnamurthymayya@gmail.com>
9 * Nikitha Malgi <nikitha01@gmail.com>
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "config.h"
31 #include <glib.h>
32 #include <epan/packet.h>
33 #include <packet-ip.h>
34 #include <epan/dissectors/packet-bfd.h>
36 /* MPLS-TP FM protocol specific variables */
37 static gint proto_mplstp_fm = -1;
38 static gint ett_mplstp_fm = -1;
39 static gint ett_mplstp_fm_flags = -1;
40 static gint ett_mplstp_fm_tlv_tree = -1;
42 static int hf_mplstp_fm_version = -1;
44 static int hf_mplstp_fm_reserved = -1;
45 static int hf_mplstp_fm_msg_type = -1;
46 static int hf_mplstp_fm_flags = -1;
47 static int hf_mplstp_fm_flags_l = -1;
48 static int hf_mplstp_fm_flags_r = -1;
49 static int hf_mplstp_fm_refresh_timer = -1;
50 static int hf_mplstp_fm_total_tlv_len = -1;
51 static int hf_mplstp_fm_if_tlv_type = -1;
52 static int hf_mplstp_fm_global_tlv_type = -1;
53 static int hf_mplstp_fm_tlv_len = -1;
54 static int hf_mplstp_fm_node_id = -1;
55 static int hf_mplstp_fm_if_num = -1;
56 static int hf_mplstp_fm_global_id = -1;
58 static const value_string fm_msg_type[] = {
59 {0, "No Return Code"},
60 {1, "Alarm-Indication Signal(A)"},
61 {2, "Lock-Report(L)"},
62 {0, NULL}
65 /* MPLS-TP Lock protocol specific variables */
66 static gint proto_mplstp_lock = -1;
67 static gint ett_mplstp_lock = -1;
69 static int hf_mplstp_lock_version = -1;
70 static int hf_mplstp_lock_reserved = -1;
71 static int hf_mplstp_lock_refresh_timer = -1;
73 static void
74 dissect_mplstp_fm_tlv (tvbuff_t *tvb, proto_tree *tree)
76 proto_item *ti;
77 proto_tree *fm_tlv_tree;
79 guint offset = 0;
81 if (!tree)
82 return;
84 ti = proto_tree_add_protocol_format (tree, proto_mplstp_fm, tvb, offset, 16,
85 "Fault-Management TLVs");
87 fm_tlv_tree = proto_item_add_subtree (ti, ett_mplstp_fm_tlv_tree);
89 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_if_tlv_type , tvb, offset,
90 1, ENC_BIG_ENDIAN);
91 offset = offset + 1;
92 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_tlv_len, tvb, offset,
93 1, ENC_BIG_ENDIAN);
94 offset = offset + 1;
95 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_node_id, tvb, offset,
96 4, ENC_BIG_ENDIAN);
97 offset = offset + 4;
98 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_if_num, tvb, offset,
99 4, ENC_BIG_ENDIAN);
100 offset = offset + 4;
101 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_global_tlv_type , tvb, offset,
102 1, ENC_BIG_ENDIAN);
103 offset = offset + 1;
104 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_tlv_len, tvb, offset,
105 1, ENC_BIG_ENDIAN);
106 offset = offset + 1;
107 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_global_id, tvb, offset,
108 4, ENC_BIG_ENDIAN);
109 /* offset = offset + 4; */
111 return;
114 /* Dissector for MPLS-TP LI protocol: RFC 6435 */
115 static void
116 dissect_mplstp_lock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
118 proto_item *ti;
119 proto_tree *lock_tree;
120 tvbuff_t *next_tvb;
122 guint8 offset = 0;
124 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-TP LI");
125 col_clear(pinfo->cinfo, COL_INFO);
127 if (!tree)
128 return;
130 ti = proto_tree_add_item(tree, proto_mplstp_lock, tvb, 0, -1, ENC_NA);
132 lock_tree = proto_item_add_subtree (ti, ett_mplstp_lock);
134 /* Version field */
135 proto_tree_add_item (lock_tree, hf_mplstp_lock_version , tvb, offset,
136 1, ENC_BIG_ENDIAN);
138 /* Reserved field */
139 proto_tree_add_item (lock_tree, hf_mplstp_lock_reserved, tvb, offset,
140 3, ENC_BIG_ENDIAN);
141 offset = offset + 3;
143 /* Refresh-Timer field */
144 proto_tree_add_item (lock_tree, hf_mplstp_lock_refresh_timer, tvb, offset,
145 1, ENC_BIG_ENDIAN);
146 offset = offset + 1;
148 /* Source-MEP TLVs */
149 next_tvb = tvb_new_subset_remaining (tvb, offset);
150 dissect_bfd_mep (next_tvb, tree, proto_mplstp_lock);
152 return;
156 /* Dissector for MPLS-TP FM protocol: RFC 6427 */
157 static void
158 dissect_mplstp_fm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
160 proto_item *ti, *ti_flags;
161 proto_tree *fm_tree, *fm_flags;
163 guint8 offset = 0;
164 guint8 tlv_len;
166 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-TP FM");
167 col_clear(pinfo->cinfo, COL_INFO);
169 tlv_len = tvb_get_guint8 (tvb, (offset + 4));
171 if (!tree)
172 return;
174 ti = proto_tree_add_item(tree, proto_mplstp_fm, tvb, 0, (tlv_len + 5), ENC_NA);
175 fm_tree = proto_item_add_subtree (ti, ett_mplstp_fm);
177 /* Version and Reserved fields */
178 proto_tree_add_item (fm_tree, hf_mplstp_fm_version , tvb, offset,
179 1, ENC_BIG_ENDIAN);
180 proto_tree_add_item (fm_tree, hf_mplstp_fm_reserved, tvb, offset,
181 1, ENC_BIG_ENDIAN);
182 offset = offset + 1;
184 /* FM-Message type field */
185 proto_tree_add_item (fm_tree, hf_mplstp_fm_msg_type, tvb, offset,
186 1,ENC_BIG_ENDIAN);
187 offset = offset + 1;
189 /* Flags field */
190 ti_flags = proto_tree_add_item (fm_tree, hf_mplstp_fm_flags, tvb,
191 offset, 1, ENC_BIG_ENDIAN);
192 fm_flags = proto_item_add_subtree(ti_flags, ett_mplstp_fm_flags);
194 proto_tree_add_item (fm_flags, hf_mplstp_fm_flags_l, tvb, offset, 1, ENC_BIG_ENDIAN);
195 proto_tree_add_item (fm_flags, hf_mplstp_fm_flags_r, tvb, offset, 1, ENC_BIG_ENDIAN);
196 offset = offset + 1;
198 /* Refresh-Timer field */
199 proto_tree_add_item (fm_tree, hf_mplstp_fm_refresh_timer, tvb, offset,
200 1, ENC_BIG_ENDIAN);
201 offset = offset + 1;
203 /* FM-TLV Length field*/
204 proto_tree_add_item (fm_tree, hf_mplstp_fm_total_tlv_len, tvb, offset,
205 1, ENC_BIG_ENDIAN);
206 offset = offset + 1;
208 if (tlv_len != 0)
210 tvbuff_t *next_tvb;
212 /* FM TLVs*/
213 next_tvb = tvb_new_subset_remaining (tvb, offset);
214 dissect_mplstp_fm_tlv (next_tvb, tree);
216 return;
219 void
220 proto_register_mplstp_lock(void)
222 static hf_register_info hf[] = {
224 {&hf_mplstp_lock_version,
225 {"Version", "mplstp_lock.version", FT_UINT8,
226 BASE_HEX, NULL, 0x0, NULL, HFILL }},
228 {&hf_mplstp_lock_reserved,
229 {"Reserved", "mplstp_lock.reserved", FT_UINT24,
230 BASE_HEX, NULL, 0x0, NULL, HFILL }},
232 {&hf_mplstp_lock_refresh_timer,
233 {"Refresh-timer value", "mplstp_lock.refresh-timer", FT_UINT8,
234 BASE_DEC, NULL, 0x0, NULL, HFILL }},
237 static gint *ett[] = {
238 &ett_mplstp_lock,
241 proto_mplstp_lock =
242 proto_register_protocol("MPLS-TP Lock-Instruct", "MPLS[-TP] Lock-Instruct "
243 "Lock-Instruct (LI) Protocol",
244 "mplstp_lock");
246 proto_register_field_array(proto_mplstp_lock, hf, array_length(hf));
247 proto_register_subtree_array(ett, array_length(ett));
249 register_dissector("mplstp_lock", dissect_mplstp_lock, proto_mplstp_lock);
252 void
253 proto_register_mplstp_fm(void)
255 static hf_register_info hf[] = {
257 {&hf_mplstp_fm_version,
258 {"Version", "mplstp_oam.version", FT_UINT8,
259 BASE_HEX, NULL, 0x0, NULL, HFILL }},
261 {&hf_mplstp_fm_reserved,
262 {"Reserved", "mplstp_oam.reserved", FT_UINT8,
263 BASE_HEX, NULL, 0x0, NULL, HFILL }},
265 {&hf_mplstp_fm_refresh_timer,
266 {"Refresh-timer value", "mplstp_oam.refresh.timer", FT_UINT8,
267 BASE_DEC, NULL, 0x0, NULL, HFILL }},
269 {&hf_mplstp_fm_total_tlv_len,
270 {"FM TLV Length", "mplstp_oam.total.tlv.len", FT_UINT8,
271 BASE_DEC, NULL, 0x0, NULL, HFILL }},
273 {&hf_mplstp_fm_if_tlv_type,
274 {"Type : IF-ID TLV", "mplstp_oam.if_id_tlv_type", FT_UINT8,
275 BASE_DEC, NULL, 0x0, NULL, HFILL }},
277 {&hf_mplstp_fm_global_tlv_type,
278 {"Type : GLOBAL-ID TLV", "mplstp_oam.global_id_tlv_type", FT_UINT8,
279 BASE_DEC, NULL, 0x0, NULL, HFILL }},
281 {&hf_mplstp_fm_tlv_len,
282 {"Length", "mplstp_oam.tlv_len", FT_UINT8,
283 BASE_DEC, NULL, 0x0, NULL, HFILL }},
285 {&hf_mplstp_fm_node_id,
286 {"Node id", "mplstp_oam.node_id", FT_IPv4,
287 BASE_NONE, NULL, 0x0, NULL, HFILL }},
289 {&hf_mplstp_fm_if_num,
290 {"Interface Number", "mplstp_oam.if_num", FT_UINT32,
291 BASE_DEC, NULL, 0x0, NULL, HFILL }},
293 {&hf_mplstp_fm_global_id,
294 {"Global id", "mplstp_oam.global_id", FT_UINT32,
295 BASE_DEC, NULL, 0x0, NULL, HFILL }},
297 {&hf_mplstp_fm_msg_type,
298 {"Message Type", "mplstp_oam.message.type", FT_UINT8,
299 BASE_DEC, VALS(fm_msg_type), 0x0, "MPLS-TP FM Message Type", HFILL }},
301 { &hf_mplstp_fm_flags,
302 { "FM Flags", "mplstp_oam.flags",
303 FT_UINT8, BASE_HEX, NULL, 0x0000, "MPLS-TP FM Flags", HFILL}
306 { &hf_mplstp_fm_flags_l,
307 { "Link Down Indication", "mplstp_oam.flag_l",
308 FT_BOOLEAN, 8, NULL, 0x0002, NULL, HFILL}
311 { &hf_mplstp_fm_flags_r,
312 { "FM Condition Cleared", "mplstp_oam.flag_r",
313 FT_BOOLEAN, 8, NULL, 0x0001, "Fault Condition Cleared", HFILL}
317 static gint *ett[] = {
318 &ett_mplstp_fm,
319 &ett_mplstp_fm_tlv_tree,
320 &ett_mplstp_fm_flags,
323 proto_mplstp_fm =
324 proto_register_protocol("MPLS-TP Fault-Management", "MPLS[-TP] Fault-Management "
325 "Fault-Management (FM) Protocol",
326 "mplstp_fm");
328 proto_register_field_array(proto_mplstp_fm, hf, array_length(hf));
329 proto_register_subtree_array(ett, array_length(ett));
331 register_dissector("mplstp_fm", dissect_mplstp_fm, proto_mplstp_fm);