Chip Boling | 8e042f6 | 2019-02-12 16:14:34 -0600 | [diff] [blame] | 1 | # Copyright 2017-present Adtran, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| 15 | """ Adtran vendor-specific OMCI Entities""" |
| 16 | |
| 17 | import inspect |
| 18 | import sys |
| 19 | import json |
| 20 | from binascii import hexlify |
| 21 | from bitstring import BitArray |
| 22 | from scapy.fields import ByteField, ShortField, BitField |
| 23 | from scapy.fields import IntField, StrFixedLenField, FieldListField, PacketLenField |
| 24 | from scapy.packet import Packet |
| 25 | from voltha.extensions.omci.omci_entities import EntityClassAttribute, \ |
| 26 | AttributeAccess, EntityOperations, EntityClass |
| 27 | |
| 28 | # abbreviations |
| 29 | ECA = EntityClassAttribute |
| 30 | AA = AttributeAccess |
| 31 | OP = EntityOperations |
| 32 | |
| 33 | |
| 34 | class OntSystem(EntityClass): |
| 35 | class_id = 65300 |
| 36 | attributes = [ |
| 37 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 38 | ECA(StrFixedLenField("time_of_day", None, 8), {AA.R, AA.W}), |
| 39 | ] |
| 40 | mandatory_operations = {OP.Get} |
| 41 | |
| 42 | |
| 43 | class VerizonOpenOMCI(EntityClass): |
| 44 | class_id = 65400 |
| 45 | attributes = [ |
| 46 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 47 | ECA(IntField("supported_specification_version", None), {AA.R}), |
| 48 | ECA(ShortField("pon_device_type", None), {AA.R}), |
| 49 | ECA(IntField("specification_in_use", None), {AA.R, AA.W}) |
| 50 | ] |
| 51 | mandatory_operations = {OP.Get, OP.Set} |
| 52 | |
| 53 | |
| 54 | class TwdmSystemProfile(EntityClass): |
| 55 | class_id = 65401 |
| 56 | attributes = [ |
| 57 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 58 | ECA(ByteField("total_twdm_channel_number", None), {AA.R}), |
| 59 | ECA(ByteField("channel_partition_index", None), {AA.R, AA.W}), |
| 60 | ECA(IntField("channel_partion_waiver_timer", None), {AA.R, AA.W}), |
| 61 | ECA(IntField("lods_re_initialization_timer", None), {AA.R, AA.W}), |
| 62 | ECA(IntField("lods_protection_timer", None), {AA.R, AA.W}), |
| 63 | ECA(IntField("downstream_tuning_timer", None), {AA.R, AA.W}), |
| 64 | ECA(IntField("upstream_tuning_timer", None), {AA.R, AA.W}), |
| 65 | ECA(StrFixedLenField("location_label_1", None, 24), {AA.R, AA.W}), |
| 66 | ECA(StrFixedLenField("location_label_2", None, 24), {AA.R, AA.W}), |
| 67 | ] |
| 68 | mandatory_operations = {OP.Get, OP.Set} |
| 69 | |
| 70 | |
| 71 | class TwdmChannel(EntityClass): |
| 72 | class_id = 65402 |
| 73 | attributes = [ |
| 74 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 75 | ECA(ByteField("active_channel_indication", None), {AA.R}), |
| 76 | ECA(ByteField("operational_channel_indication", None), {AA.R}), |
| 77 | ECA(ByteField("downstream_wavelength_channel", None), {AA.R}), |
| 78 | ECA(ByteField("upstream_wavelength_channel", None), {AA.R}), |
| 79 | ] |
| 80 | mandatory_operations = {OP.Get} |
| 81 | |
| 82 | |
| 83 | class WatchdogConfigData(EntityClass): |
| 84 | class_id = 65403 |
| 85 | attributes = [ |
| 86 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 87 | ECA(IntField("upstream_transmission_timing_drift_self_monitoring_capability", None), {AA.R}), |
| 88 | ECA(IntField("upstream_transmission_wavelength_drift_self_monitoring_capability", None), {AA.R}), |
| 89 | ECA(IntField("upstream_transmission_optical_power_self_monitoring_capability", None), {AA.R}), |
| 90 | ECA(IntField("mean_out_of_channel_optical_power_spectral_density_self_monitoring_capability", None), {AA.R}), |
| 91 | ECA(IntField("mean_optical_power_spectral_density_self_monitoring_capability", None), {AA.R}), |
| 92 | ] |
| 93 | mandatory_operations = {OP.Get} |
| 94 | |
| 95 | |
| 96 | class FlexibleConfigurationStatusPortal(EntityClass): |
| 97 | class_id = 65420 |
| 98 | attributes = [ |
| 99 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 100 | ECA(IntField("service_instance", None), {AA.R, AA.W}), |
| 101 | ECA(ShortField("configuration_method", None), {AA.R, AA.W}), |
| 102 | ECA(ShortField("network_address", None), {AA.R, AA.W}), |
| 103 | ECA(ByteField("administrative_state", None), {AA.R, AA}), |
| 104 | ECA(ByteField("operational_state", None), {AA.R}, avc=True), |
| 105 | ECA(ShortField("cause_for_last_abnormal_halt", None), {AA.R}), |
| 106 | ECA(ShortField("configuration_portal_update_available", None), {AA.R, AA.W}), |
| 107 | ECA(StrFixedLenField("configuration_portal_table", None, 25), {AA.R, AA.W}), |
| 108 | ECA(ByteField("configuration_portal_result", None), {AA.R, AA.W}, avc=True), |
| 109 | ECA(ShortField("status_message_available", None), {AA.R, AA.W}, avc=True), |
| 110 | ECA(ByteField("status_message", None), {AA.R, AA.W}), |
| 111 | ECA(ByteField("status_message_result", None), {AA.R, AA.W}), |
| 112 | ECA(ShortField("associated_me_class", None), {AA.R}), |
| 113 | ECA(ShortField("associated_me_class_instance", None), {AA.R}), |
| 114 | ] |
| 115 | mandatory_operations = {OP.Get, OP.Set, OP.Create, OP.Delete, OP.GetNext, OP.SetTable} |
| 116 | |
| 117 | |
| 118 | class Onu3G(EntityClass): |
| 119 | class_id = 65422 |
| 120 | attributes = [ |
| 121 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 122 | ECA(ByteField("flash_memory_performance_value", None), {AA.R}), |
| 123 | ECA(ByteField("latest_restart_reason", None), {AA.R}), |
| 124 | ECA(ShortField("total_number_of_status_snapshots", None), {AA.R}), |
| 125 | ECA(ShortField("number_of_valid_status_snapshots", None), {AA.R}), |
| 126 | ECA(ShortField("next_status_snapshot_index", None), {AA.R}), |
| 127 | ECA(ByteField("status_snapshot_record_table", None), {AA.R}), # TODO: MxN field |
| 128 | ECA(ByteField("snap_action", None), {AA.W}), |
| 129 | ECA(ByteField("most_recent_status_snapshot", None), {AA.R}), # TODO: N field |
| 130 | ECA(ByteField("reset_action", None), {AA.W}), |
| 131 | ] |
| 132 | mandatory_operations = {OP.Get, OP.Set, OP.GetNext} |
| 133 | |
| 134 | |
| 135 | class AdtnVlanTaggingOperation(Packet): |
| 136 | name = "VlanTaggingOperation" |
| 137 | fields_desc = [ |
| 138 | BitField("filter_outer_priority", 0, 4), |
| 139 | BitField("filter_outer_vid", 0, 13), |
| 140 | BitField("filter_outer_tpid_de", 0, 3), |
| 141 | BitField("pad1", 0, 12), |
| 142 | |
| 143 | BitField("filter_inner_priority", 0, 4), |
| 144 | BitField("filter_inner_vid", 0, 13), |
| 145 | BitField("filter_inner_tpid_de", 0, 3), |
| 146 | BitField("pad2", 0, 8), |
| 147 | BitField("filter_ether_type", 0, 4), |
| 148 | |
| 149 | BitField("treatment_tags_to_remove", 0, 2), |
| 150 | BitField("pad3", 0, 10), |
| 151 | BitField("treatment_outer_priority", 0, 4), |
| 152 | BitField("treatment_outer_vid", 0, 13), |
| 153 | BitField("treatment_outer_tpid_de", 0, 3), |
| 154 | |
| 155 | BitField("pad4", 0, 12), |
| 156 | BitField("treatment_inner_priority", 0, 4), |
| 157 | BitField("treatment_inner_vid", 0, 13), |
| 158 | BitField("treatment_inner_tpid_de", 0, 3), |
| 159 | ] |
| 160 | |
| 161 | def to_json(self): |
| 162 | return json.dumps(self.fields, separators=(',', ':')) |
| 163 | |
| 164 | @staticmethod |
| 165 | def json_from_value(value): |
| 166 | bits = BitArray(hex=hexlify(value)) |
| 167 | temp = AdtnVlanTaggingOperation( |
| 168 | filter_outer_priority=bits[0:4].uint, # 4 <-size |
| 169 | filter_outer_vid=bits[4:17].uint, # 13 |
| 170 | filter_outer_tpid_de=bits[17:20].uint, # 3 |
| 171 | # pad 12 |
| 172 | filter_inner_priority=bits[32:36].uint, # 4 |
| 173 | filter_inner_vid=bits[36:49].uint, # 13 |
| 174 | filter_inner_tpid_de=bits[49:52].uint, # 3 |
| 175 | # pad 8 |
| 176 | filter_ether_type=bits[60:64].uint, # 4 |
| 177 | treatment_tags_to_remove=bits[64:66].uint, # 2 |
| 178 | # pad 10 |
| 179 | treatment_outer_priority=bits[76:80].uint, # 4 |
| 180 | treatment_outer_vid=bits[80:93].uint, # 13 |
| 181 | treatment_outer_tpid_de=bits[93:96].uint, # 3 |
| 182 | # pad 12 |
| 183 | treatment_inner_priority=bits[108:112].uint, # 4 |
| 184 | treatment_inner_vid=bits[112:125].uint, # 13 |
| 185 | treatment_inner_tpid_de=bits[125:128].uint, # 3 |
| 186 | ) |
| 187 | return json.dumps(temp.fields, separators=(',', ':')) |
| 188 | |
| 189 | def index(self): |
| 190 | return '{:02}'.format(self.fields.get('filter_outer_priority',0)) + \ |
| 191 | '{:03}'.format(self.fields.get('filter_outer_vid',0)) + \ |
| 192 | '{:01}'.format(self.fields.get('filter_outer_tpid_de',0)) + \ |
| 193 | '{:03}'.format(self.fields.get('filter_inner_priority',0)) + \ |
| 194 | '{:04}'.format(self.fields.get('filter_inner_vid',0)) + \ |
| 195 | '{:01}'.format(self.fields.get('filter_inner_tpid_de',0)) + \ |
| 196 | '{:02}'.format(self.fields.get('filter_ether_type',0)) |
| 197 | |
| 198 | def is_delete(self): |
| 199 | return self.fields.get('treatment_tags_to_remove',0) == 0x3 and \ |
| 200 | self.fields.get('pad3',0) == 0x3ff and \ |
| 201 | self.fields.get('treatment_outer_priority',0) == 0xf and \ |
| 202 | self.fields.get('treatment_outer_vid',0) == 0x1fff and \ |
| 203 | self.fields.get('treatment_outer_tpid_de',0) == 0x7 and \ |
| 204 | self.fields.get('pad4',0) == 0xfff and \ |
| 205 | self.fields.get('treatment_inner_priority',0) == 0xf and \ |
| 206 | self.fields.get('treatment_inner_vid',0) == 0x1fff and \ |
| 207 | self.fields.get('treatment_inner_tpid_de',0) == 0x7 |
| 208 | |
| 209 | def delete(self): |
| 210 | self.fields['treatment_tags_to_remove'] = 0x3 |
| 211 | self.fields['pad3'] = 0x3ff |
| 212 | self.fields['treatment_outer_priority'] = 0xf |
| 213 | self.fields['treatment_outer_vid'] = 0x1fff |
| 214 | self.fields['treatment_outer_tpid_de'] = 0x7 |
| 215 | self.fields['pad4'] = 0xfff |
| 216 | self.fields['treatment_inner_priority'] = 0xf |
| 217 | self.fields['treatment_inner_vid'] = 0x1fff |
| 218 | self.fields['treatment_inner_tpid_de'] = 0x7 |
| 219 | return self |
| 220 | |
| 221 | |
| 222 | class AdtnExtendedVlanTaggingOperationConfigurationData(EntityClass): |
| 223 | class_id = 171 |
| 224 | attributes = [ |
| 225 | ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}), |
| 226 | ECA(ByteField("association_type", None), {AA.R, AA.W, AA.SBC}, |
| 227 | range_check=lambda x: 0 <= x <= 11), |
| 228 | ECA(ShortField("received_vlan_tagging_operation_table_max_size", None), |
| 229 | {AA.R}), |
| 230 | ECA(ShortField("input_tpid", None), {AA.R, AA.W}), |
| 231 | ECA(ShortField("output_tpid", None), {AA.R, AA.W}), |
| 232 | ECA(ByteField("downstream_mode", None), {AA.R, AA.W}, |
| 233 | range_check=lambda x: 0 <= x <= 8), |
| 234 | ECA(StrFixedLenField("received_frame_vlan_tagging_operation_table", |
| 235 | AdtnVlanTaggingOperation, 16), {AA.R, AA.W}), |
| 236 | ECA(ShortField("associated_me_pointer", None), {AA.R, AA.W, AA.SBC}), |
| 237 | ECA(FieldListField("dscp_to_p_bit_mapping", None, |
| 238 | BitField('', 0, size=3), count_from=lambda _: 64), |
| 239 | {AA.R, AA.W}), |
| 240 | ] |
| 241 | mandatory_operations = {OP.Create, OP.Delete, OP.Set, OP.Get, OP.GetNext} |
| 242 | optional_operations = {OP.SetTable} |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | ################################################################################# |
| 248 | # entity class lookup table from entity_class values |
| 249 | _onu_entity_classes_name_map = dict( |
| 250 | inspect.getmembers(sys.modules[__name__], lambda o: |
| 251 | inspect.isclass(o) and issubclass(o, EntityClass) and o is not EntityClass) |
| 252 | ) |
| 253 | _onu_custom_entity_classes = [c for c in _onu_entity_classes_name_map.itervalues()] |
| 254 | _onu_custom_entity_id_to_class_map = dict() |
| 255 | |
| 256 | |
| 257 | def onu_custom_me_entities(): |
| 258 | if len(_onu_custom_entity_id_to_class_map) == 0: |
| 259 | for entity_class in _onu_custom_entity_classes: |
| 260 | assert entity_class.class_id not in _onu_custom_entity_id_to_class_map, \ |
| 261 | "Class ID '{}' already exists in the class map".format(entity_class.class_id) |
| 262 | _onu_custom_entity_id_to_class_map[entity_class.class_id] = entity_class |
| 263 | |
| 264 | return _onu_custom_entity_id_to_class_map |
| 265 | |