blob: 4554bdbe37bc041029d430b23b6893b2878eb374 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#!/usr/bin/env python
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#--------------------------------------------------------------------------#
16# Copyright (C) 2015 - 2016 by Tibit Communications, Inc. #
17# All rights reserved. #
18# #
19# _______ ____ _ ______ #
20# /_ __(_) __ )(_)_ __/ #
21# / / / / __ / / / / #
22# / / / / /_/ / / / / #
23# /_/ /_/_____/_/ /_/ #
24# #
25#--------------------------------------------------------------------------#
26
27import sys
28import inspect
29
30# SCAPY-specific imports
31from scapy.packet import Packet, bind_layers
32from scapy.fields import StrField, PacketField, X3BytesField
33from scapy.layers.l2 import Ether
34
35from EOAM_TLV import *
36
37# Layer 2 definitions
38EOAM_MULTICAST_ADDRESS = '01:80:c2:00:00:02' # Well-known OAM Multicast address
39UNUSED_SOURCE_ADDRESS = '12:34:56:78:9a:bc' # for OAM frames sent over the CLI
40IGMP_MULTICAST_ADDRESS = '01:00:5e:00:00:01' # IGMP Multicast address
41OAM_ETHERTYPE = 0xA8C8 # Ethertype value used to identify a 1904.2 message
42
43VENDOR_SPECIFIC_OPCODE = 0xFE
44CABLELABS_OUI = 0x001000 # CableLabs OUI (used for DPoE OAM messages)
45TIBIT_OUI = 0x2AEA15 # Tibit OUI
46ITU_OUI = 0x0019A7 # ITU OUI - used to encapsulate OMCI messages
47
48# Message Types which can be received from the Tibit OLT, Tibit ONU, DPoE ONU, or GPON ONT
49# ove the 1904.2 transport
50RxedOamMsgTypeEnum = {
51 "Unknown" : 0x00,
52 "Info" : 0x01, # Info PDU
53 "Event Notification" : 0x02, # Event Notification - Tibit or DPoE Event
54 "DPoE Get Response" : 0x03, # DPoE Get Response
55 "DPoE Set Response" : 0x04, # DPoE Set Rewponse
56 "DPoE File Transfer" : 0x05, # Specifically - a File Transfer ACK
57 "OMCI Message" : 0x06, # Contains an embedded OMCI message
58 }
59
60RxedOamMsgTypes = {v: k for k, v in RxedOamMsgTypeEnum.iteritems()}
61
62
63###############################################################
64# SCAPY Layer definitions used to parse 1904.2 messages
65###############################################################
66
67# OAM fields after the L2 addressing/VLAN tags
68# when the Ethertype is set to 0xA8C8
69class EOAMPayload(Packet):
70 name = 'EOAM Payload'
71 fields_desc = [
72 ByteEnumField("subtype", 0x03, SlowProtocolsSubtypeEnum),
73 XShortField("flags", 0x0050),
74 XByteField("opcode", VENDOR_SPECIFIC_OPCODE),
75 ]
76
77bind_layers(Ether, EOAMPayload, type=OAM_ETHERTYPE)
78
79
80# 1904.1 OAM Event
81class EOAM_EventMsg(Packet):
82 name = 'EOAM Event'
83 fields_desc = [
84 XShortField("sequence", 0x0001),
85 XByteField("tlv_type", VENDOR_SPECIFIC_OPCODE),
86 XByteField("length", 0x01),
87 X3BytesField("oui", CABLELABS_OUI),
88 PacketField("body", None, Packet),
89 ]
90
91bind_layers(EOAMPayload, EOAM_EventMsg, opcode=0x01)
92
93# Vendor-specific OAM message
94# indicated by an Opcode field set to 0xFE
95class EOAM_VendSpecificMsg(Packet):
96 name = "Vendor-Specific OAM"
97 fields_desc = [
98 X3BytesField("oui", CABLELABS_OUI),
99 ]
100
101bind_layers(EOAMPayload, EOAM_VendSpecificMsg, opcode=VENDOR_SPECIFIC_OPCODE)
102
103# Tibit-specific OAM message
104# indicated by an OUI set to 0x2AEA15
105class EOAM_TibitMsg(Packet):
106 name = "Tibit OAM Message"
107 fields_desc = [
108 ByteEnumField("dpoe_opcode", 0x01, DPoEOpcodeEnum),
109 PacketField("body", None, Packet),
110 ]
111
112bind_layers(EOAM_VendSpecificMsg, EOAM_TibitMsg, oui=TIBIT_OUI)
113
114# DPoE-specific OAM message
115# indicated by an OUI set to 0x001000
116class EOAM_DpoeMsg(Packet):
117 name = "DPoE OAM Message"
118 fields_desc = [
119 ByteEnumField("dpoe_opcode", 0x01, DPoEOpcodeEnum),
120 PacketField("body", None, Packet),
121 ]
122
123bind_layers(EOAM_VendSpecificMsg, EOAM_DpoeMsg, oui=CABLELABS_OUI)
124
125# Embedded OMCI message
126# indicated by an OUI set to ITU OUI (0x0019A7)
127
128#class EOAM_OmciMsg(Packet):
129# name = "OAM-encapsulated OMCI Message"
130# fields_desc = [
131# XShortField("trans_id", 1),
132# XByteField("msg_type", 0x49),
133# XByteField("dev_id", 0x0A),
134# XShortField("me_class", 0x0000),
135# XShortField("me_inst", 0x0000),
136# PacketField("body", None, Packet),
137# ]
138
139class EOAM_OmciMsg(Packet):
140 name = "OAM-encapsulated OMCI Message"
141 fields_desc = [
142 PacketField("body", None, Packet),
143 ]
144
145bind_layers(EOAM_VendSpecificMsg, EOAM_OmciMsg, oui=ITU_OUI)
146
147###############################################################
148# End of SCAPY Layers
149###############################################################
150
151
152