Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 1 | # |
Zsolt Haraszti | 3eb27a5 | 2017-01-03 21:56:48 -0800 | [diff] [blame] | 2 | # Copyright 2017 the original author or authors. |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 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 | |
| 17 | """ |
| 18 | Tibit OLT device adapter |
| 19 | """ |
Zsolt Haraszti | 4ef0a9a | 2016-12-20 01:35:48 -0800 | [diff] [blame] | 20 | import json |
Zsolt Haraszti | 4ef0a9a | 2016-12-20 01:35:48 -0800 | [diff] [blame] | 21 | from uuid import uuid4 |
| 22 | |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 23 | import structlog |
| 24 | from scapy.fields import StrField |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 25 | from scapy.layers.l2 import Ether, Dot1Q |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 26 | from scapy.packet import Packet, bind_layers |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 27 | from twisted.internet import reactor |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 28 | from twisted.internet.defer import DeferredQueue, inlineCallbacks |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 29 | from zope.interface import implementer |
| 30 | |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 31 | from common.frameio.frameio import BpfProgramFilter, hexify |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 32 | from voltha.adapters.interface import IAdapterInterface |
Nathan Knuth | 31c3696 | 2016-12-27 10:04:49 -0800 | [diff] [blame] | 33 | from voltha.extensions.eoam.EOAM import EOAMPayload, DPoEOpcode_SetRequest |
| 34 | from voltha.extensions.eoam.EOAM_TLV import DOLTObject, \ |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 35 | NetworkToNetworkPortObject, OLTUnicastLogicalLink, \ |
| 36 | PortIngressRuleClauseMatchLength01, AddStaticMacAddress, \ |
| 37 | PortIngressRuleClauseMatchLength02, PortIngressRuleResultForward, \ |
| 38 | PortIngressRuleResultSet, PortIngressRuleResultInsert, \ |
| 39 | PortIngressRuleResultCopy, PortIngressRuleResultReplace, \ |
| 40 | PortIngressRuleResultDelete, PortIngressRuleResultOLTQueue, \ |
| 41 | PortIngressRuleTerminator, AddPortIngressRule, CablelabsOUI, PonPortObject |
Nathan Knuth | 31c3696 | 2016-12-27 10:04:49 -0800 | [diff] [blame] | 42 | from voltha.extensions.eoam.EOAM_TLV import PortIngressRuleHeader |
Nathan Knuth | d390ceb | 2017-01-07 15:38:58 -0800 | [diff] [blame] | 43 | from voltha.extensions.eoam.EOAM_TLV import ClauseSubtypeEnum |
| 44 | from voltha.extensions.eoam.EOAM_TLV import RuleOperatorEnum |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 45 | from voltha.core.flow_decomposer import * |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 46 | from voltha.core.logical_device_agent import mac_str_to_tuple |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 47 | from voltha.protos.adapter_pb2 import Adapter, AdapterConfig |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 48 | from voltha.protos.common_pb2 import LogLevel, ConnectStatus |
| 49 | from voltha.protos.common_pb2 import OperStatus, AdminState |
Zsolt Haraszti | 4ef0a9a | 2016-12-20 01:35:48 -0800 | [diff] [blame] | 50 | from voltha.protos.device_pb2 import Device, Port |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 51 | from voltha.protos.device_pb2 import DeviceType, DeviceTypes |
| 52 | from voltha.protos.health_pb2 import HealthStatus |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 53 | from voltha.protos.logical_device_pb2 import LogicalDevice, LogicalPort |
| 54 | from voltha.protos.openflow_13_pb2 import ofp_desc, ofp_port, OFPPF_10GB_FD, \ |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 55 | OFPPF_FIBER, OFPPS_LIVE, ofp_switch_features, OFPC_PORT_STATS, \ |
| 56 | OFPC_GROUP_STATS, OFPC_TABLE_STATS, OFPC_FLOW_STATS |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 57 | from voltha.registry import registry |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 58 | log = structlog.get_logger() |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 59 | |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 60 | # Match on the MGMT VLAN, Priority 7 |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 61 | TIBIT_MGMT_VLAN = 4090 |
| 62 | TIBIT_MGMT_PRIORITY = 7 |
| 63 | frame_match_case1 = 'ether[14:2] = 0x{:01x}{:03x}'.format( |
| 64 | TIBIT_MGMT_PRIORITY << 1, TIBIT_MGMT_VLAN) |
| 65 | |
| 66 | TIBIT_PACKET_IN_VLAN = 4000 |
| 67 | frame_match_case2 = '(ether[14:2] & 0xfff) = 0x{:03x}'.format( |
| 68 | TIBIT_PACKET_IN_VLAN) |
| 69 | |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 70 | TIBIT_PACKET_OUT_VLAN = 4000 |
| 71 | |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 72 | is_tibit_frame = BpfProgramFilter('{} or {}'.format( |
| 73 | frame_match_case1, frame_match_case2)) |
| 74 | |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 75 | #is_tibit_frame = lambda x: True |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 76 | |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 77 | # Extract OLT MAC address: This is a good |
| 78 | # example of getting the OLT mac address |
| 79 | |
| 80 | #for mac, device in self.device_ids.iteritems(): |
| 81 | # if device == dev_id: |
| 82 | # olt_mac_address = mac |
| 83 | # log.info('packet-out', olt_mac_address=olt_mac_address) |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 84 | |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 85 | # To be removed in favor of OAM |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 86 | class TBJSON(Packet): |
| 87 | """ TBJSON 'packet' layer. """ |
| 88 | name = "TBJSON" |
| 89 | fields_desc = [StrField("data", default="")] |
| 90 | |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 91 | bind_layers(Ether, TBJSON, type=0x9001) |
Zsolt Haraszti | 4ef0a9a | 2016-12-20 01:35:48 -0800 | [diff] [blame] | 92 | |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 93 | SUMITOMO_ELECTRIC_INDUSTRIES_OUI=u"0025DC" |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 94 | |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 95 | @implementer(IAdapterInterface) |
| 96 | class TibitOltAdapter(object): |
| 97 | |
| 98 | name = 'tibit_olt' |
| 99 | |
| 100 | supported_device_types = [ |
| 101 | DeviceType( |
| 102 | id='tibit_olt', |
| 103 | adapter=name, |
| 104 | accepts_bulk_flow_update=True |
| 105 | ) |
| 106 | ] |
| 107 | |
| 108 | def __init__(self, adapter_agent, config): |
| 109 | self.adapter_agent = adapter_agent |
| 110 | self.config = config |
| 111 | self.descriptor = Adapter( |
| 112 | id=self.name, |
| 113 | vendor='Tibit Communications Inc.', |
| 114 | version='0.1', |
| 115 | config=AdapterConfig(log_level=LogLevel.INFO) |
| 116 | ) |
Zsolt Haraszti | a17f3ec | 2016-12-08 14:55:49 -0800 | [diff] [blame] | 117 | self.interface = registry('main').get_args().interface |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 118 | self.io_port = None |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 119 | self.incoming_queues = {} # OLT mac_address -> DeferredQueue() |
| 120 | self.device_ids = {} # OLT mac_address -> device_id |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 121 | self.vlan_to_device_ids = {} # c-vid -> (device_id, logical_device_id) |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 122 | |
| 123 | def start(self): |
Zsolt Haraszti | a17f3ec | 2016-12-08 14:55:49 -0800 | [diff] [blame] | 124 | log.debug('starting', interface=self.interface) |
| 125 | log.info('started', interface=self.interface) |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 126 | |
| 127 | def stop(self): |
| 128 | log.debug('stopping') |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 129 | if self.io_port is not None: |
| 130 | registry('frameio').del_interface(self.interface) |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 131 | log.info('stopped') |
| 132 | |
| 133 | def adapter_descriptor(self): |
| 134 | return self.descriptor |
| 135 | |
| 136 | def device_types(self): |
| 137 | return DeviceTypes(items=self.supported_device_types) |
| 138 | |
| 139 | def health(self): |
| 140 | return HealthStatus(state=HealthStatus.HealthState.HEALTHY) |
| 141 | |
| 142 | def change_master_state(self, master): |
| 143 | raise NotImplementedError() |
| 144 | |
| 145 | def adopt_device(self, device): |
| 146 | log.info('adopt-device', device=device) |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 147 | self._activate_io_port() |
| 148 | reactor.callLater(0, self._launch_device_activation, device) |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 149 | |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 150 | def _activate_io_port(self): |
| 151 | if self.io_port is None: |
| 152 | self.io_port = registry('frameio').add_interface( |
| 153 | self.interface, self._rcv_io, is_tibit_frame) |
| 154 | |
| 155 | @inlineCallbacks |
| 156 | def _launch_device_activation(self, device): |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 157 | try: |
| 158 | log.debug('launch_dev_activation') |
| 159 | # prepare receive queue |
| 160 | self.incoming_queues[device.mac_address] = DeferredQueue(size=100) |
| 161 | |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 162 | # add mac_address to device_ids table |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 163 | olt_mac = device.mac_address |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 164 | self.device_ids[olt_mac] = device.id |
| 165 | |
| 166 | # send out ping to OLT device |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 167 | ping_frame = self._make_ping_frame(mac_address=olt_mac) |
| 168 | self.io_port.send(ping_frame) |
| 169 | |
| 170 | # wait till we receive a response |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 171 | ## TODO add timeout mechanism so we can signal if we cannot reach |
| 172 | ##device |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 173 | while True: |
| 174 | response = yield self.incoming_queues[olt_mac].get() |
| 175 | # verify response and if not the expected response |
| 176 | if 1: # TODO check if it is really what we expect, and wait if not |
| 177 | break |
| 178 | |
| 179 | except Exception, e: |
| 180 | log.exception('launch device failed', e=e) |
| 181 | |
| 182 | # if we got response, we can fill out the device info, mark the device |
| 183 | # reachable |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 184 | # jdev = json.loads(response.data[5:]) |
| 185 | jdev = json.loads(response.payload.payload.body.load) |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 186 | device.root = True |
Zsolt Haraszti | 4ef0a9a | 2016-12-20 01:35:48 -0800 | [diff] [blame] | 187 | device.vendor = 'Tibit Communications, Inc.' |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 188 | device.model = jdev.get('results', {}).get('device', 'DEVICE_UNKNOWN') |
Zsolt Haraszti | 4ef0a9a | 2016-12-20 01:35:48 -0800 | [diff] [blame] | 189 | device.hardware_version = jdev['results']['datecode'] |
| 190 | device.firmware_version = jdev['results']['firmware'] |
| 191 | device.software_version = jdev['results']['modelversion'] |
| 192 | device.serial_number = jdev['results']['manufacturer'] |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 193 | |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 194 | device.connect_status = ConnectStatus.REACHABLE |
| 195 | self.adapter_agent.update_device(device) |
| 196 | |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 197 | # then shortly after we create some ports for the device |
| 198 | log.info('create-port') |
| 199 | nni_port = Port( |
| 200 | port_no=2, |
| 201 | label='NNI facing Ethernet port', |
| 202 | type=Port.ETHERNET_NNI, |
| 203 | admin_state=AdminState.ENABLED, |
| 204 | oper_status=OperStatus.ACTIVE |
| 205 | ) |
| 206 | self.adapter_agent.add_port(device.id, nni_port) |
| 207 | self.adapter_agent.add_port(device.id, Port( |
| 208 | port_no=1, |
| 209 | label='PON port', |
| 210 | type=Port.PON_OLT, |
| 211 | admin_state=AdminState.ENABLED, |
| 212 | oper_status=OperStatus.ACTIVE |
| 213 | )) |
| 214 | |
| 215 | log.info('create-logical-device') |
| 216 | # then shortly after we create the logical device with one port |
| 217 | # that will correspond to the NNI port |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 218 | ld = LogicalDevice( |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 219 | desc=ofp_desc( |
| 220 | mfr_desc=device.vendor, |
| 221 | hw_desc=jdev['results']['device'], |
| 222 | sw_desc=jdev['results']['firmware'], |
| 223 | serial_num=uuid4().hex, |
| 224 | dp_desc='n/a' |
| 225 | ), |
| 226 | switch_features=ofp_switch_features( |
| 227 | n_buffers=256, # TODO fake for now |
| 228 | n_tables=2, # TODO ditto |
| 229 | capabilities=( # TODO and ditto |
| 230 | OFPC_FLOW_STATS |
| 231 | | OFPC_TABLE_STATS |
| 232 | | OFPC_PORT_STATS |
| 233 | | OFPC_GROUP_STATS |
| 234 | ) |
| 235 | ), |
| 236 | root_device_id=device.id |
| 237 | ) |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 238 | ld_initialized = self.adapter_agent.create_logical_device(ld) |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 239 | cap = OFPPF_10GB_FD | OFPPF_FIBER |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 240 | self.adapter_agent.add_logical_port(ld_initialized.id, LogicalPort( |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 241 | id='nni', |
| 242 | ofp_port=ofp_port( |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 243 | port_no=0, |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 244 | hw_addr=mac_str_to_tuple(device.mac_address), |
| 245 | name='nni', |
| 246 | config=0, |
| 247 | state=OFPPS_LIVE, |
| 248 | curr=cap, |
| 249 | advertised=cap, |
| 250 | peer=cap, |
| 251 | curr_speed=OFPPF_10GB_FD, |
| 252 | max_speed=OFPPF_10GB_FD |
| 253 | ), |
| 254 | device_id=device.id, |
| 255 | device_port_no=nni_port.port_no, |
| 256 | root_port=True |
| 257 | )) |
| 258 | |
| 259 | # and finally update to active |
| 260 | device = self.adapter_agent.get_device(device.id) |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 261 | device.parent_id = ld_initialized.id |
Zsolt Haraszti | aa4626e | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 262 | device.oper_status = OperStatus.ACTIVE |
| 263 | self.adapter_agent.update_device(device) |
| 264 | |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 265 | # Just transitioned to ACTIVE, wait a tenth of second |
| 266 | # before checking for ONUs |
| 267 | reactor.callLater(0.1, self._detect_onus, device) |
| 268 | |
| 269 | @inlineCallbacks |
| 270 | def _detect_onus(self, device): |
| 271 | # send out get 'links' to the OLT device |
| 272 | olt_mac = device.mac_address |
| 273 | links_frame = self._make_links_frame(mac_address=olt_mac) |
| 274 | self.io_port.send(links_frame) |
| 275 | while True: |
| 276 | response = yield self.incoming_queues[olt_mac].get() |
| 277 | # verify response and if not the expected response |
| 278 | if 1: # TODO check if it is really what we expect, and wait if not |
| 279 | break |
| 280 | |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 281 | jdev = json.loads(response.payload.payload.body.load) |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 282 | onu_mac = '' |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 283 | for macid in jdev['results']: |
| 284 | if macid['macid'] is None: |
| 285 | log.info('MAC ID is NONE %s' % str(macid['macid'])) |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 286 | elif macid['macid'][:6].upper() == SUMITOMO_ELECTRIC_INDUSTRIES_OUI: |
| 287 | onu_mac = macid['macid'] |
| 288 | log.info('SUMITOMO mac address %s' % str(macid['macid'])) |
| 289 | log.info('activate-olt-for-onu-%s' % onu_mac) |
| 290 | # Convert from string to colon separated form |
| 291 | onu_mac = ':'.join(s.encode('hex') for s in onu_mac.decode('hex')) |
| 292 | vlan_id = self._olt_side_onu_activation(int(macid['macid'][-4:-2], 16)) |
| 293 | self.adapter_agent.child_device_detected( |
| 294 | parent_device_id=device.id, |
| 295 | parent_port_no=1, |
| 296 | child_device_type='dpoe_onu', |
| 297 | mac_address = onu_mac, |
| 298 | proxy_address=Device.ProxyAddress( |
| 299 | device_id=device.id, |
| 300 | channel_id=vlan_id |
| 301 | ), |
| 302 | vlan=vlan_id |
| 303 | ) |
| 304 | |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 305 | else: |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 306 | onu_mac = '000c' + macid.get('macid', 'e2000000')[4:] |
| 307 | log.info('activate-olt-for-onu-%s' % onu_mac) |
| 308 | # Convert from string to colon separated form |
| 309 | onu_mac = ':'.join(s.encode('hex') for s in onu_mac.decode('hex')) |
| 310 | vlan_id = self._olt_side_onu_activation(int(macid['macid'][-4:-2], 16)) |
| 311 | self.adapter_agent.child_device_detected( |
| 312 | parent_device_id=device.id, |
| 313 | parent_port_no=1, |
| 314 | child_device_type='tibit_onu', |
| 315 | mac_address = onu_mac, |
| 316 | proxy_address=Device.ProxyAddress( |
| 317 | device_id=device.id, |
| 318 | channel_id=vlan_id |
| 319 | ), |
| 320 | vlan=vlan_id |
| 321 | ) |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 322 | |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 323 | # also record the vlan_id -> (device_id, logical_device_id) for |
| 324 | # later use |
| 325 | self.vlan_to_device_ids[vlan_id] = (device.id, device.parent_id) |
| 326 | |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 327 | def _olt_side_onu_activation(self, serial): |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 328 | """ |
| 329 | This is where if this was a real OLT, the OLT-side activation for |
| 330 | the new ONU should be performed. By the time we return, the OLT shall |
| 331 | be able to provide tunneled (proxy) communication to the given ONU, |
| 332 | using the returned information. |
| 333 | """ |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 334 | vlan_id = serial + 200 |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 335 | return vlan_id |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 336 | |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 337 | def _rcv_io(self, port, frame): |
| 338 | |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 339 | log.info('frame-received', frame=hexify(frame)) |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 340 | |
Zsolt Haraszti | 4ef0a9a | 2016-12-20 01:35:48 -0800 | [diff] [blame] | 341 | # make into frame to extract source mac |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 342 | response = Ether(frame) |
| 343 | |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 344 | if response.haslayer(Dot1Q): |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 345 | |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 346 | # All OAM responses from the OLT should have a TIBIT_MGMT_VLAN. |
| 347 | # Responses from the ONUs should have a TIBIT_MGMT_VLAN followed by a ONU CTAG |
| 348 | # All packet-in frames will have the TIBIT_PACKET_IN_VLAN. |
| 349 | if response.getlayer(Dot1Q).type == 0x8100: |
| 350 | |
| 351 | if response.getlayer(Dot1Q).vlan == TIBIT_PACKET_IN_VLAN: |
| 352 | |
| 353 | inner_tag_and_rest = response.payload.payload |
| 354 | |
| 355 | inner_tag_and_rest.show() # TODO remove this soon |
| 356 | |
| 357 | if isinstance(inner_tag_and_rest, Dot1Q): |
| 358 | |
| 359 | cvid = inner_tag_and_rest.vlan |
| 360 | |
| 361 | frame = Ether(src=response.src, |
| 362 | dst=response.dst, |
| 363 | type=inner_tag_and_rest.type) /\ |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 364 | inner_tag_and_rest.payload |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 365 | |
| 366 | _, logical_device_id = self.vlan_to_device_ids.get(cvid) |
| 367 | if logical_device_id is None: |
| 368 | log.error('invalid-cvid', cvid=cvid) |
| 369 | else: |
| 370 | self.adapter_agent.send_packet_in( |
| 371 | logical_device_id=logical_device_id, |
| 372 | logical_port_no=cvid, # C-VID encodes port no |
| 373 | packet=str(frame)) |
| 374 | |
| 375 | else: |
| 376 | log.error('packet-in-single-tagged', |
| 377 | frame=hexify(response)) |
| 378 | |
| 379 | else: |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 380 | ## Mgmt responses received from the ONU |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 381 | ## Since the type of the first layer is 0x8100, |
| 382 | ## then the frame must have an inner tag layer |
| 383 | olt_mac = response.src |
| 384 | device_id = self.device_ids[olt_mac] |
| 385 | channel_id = response[Dot1Q:2].vlan |
| 386 | log.info('received_channel_id', channel_id=channel_id, |
| 387 | device_id=device_id) |
| 388 | |
| 389 | proxy_address=Device.ProxyAddress( |
| 390 | device_id=device_id, |
| 391 | channel_id=channel_id |
| 392 | ) |
| 393 | # pop dot1q header(s) |
| 394 | msg = response.payload.payload |
| 395 | self.adapter_agent.receive_proxied_message(proxy_address, msg) |
| 396 | |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 397 | else: |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 398 | ## Mgmt responses received from the OLT |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 399 | ## enqueue incoming parsed frame to right device |
Zsolt Haraszti | 313c4be | 2016-12-27 11:06:53 -0800 | [diff] [blame] | 400 | log.info('received-dot1q-not-8100') |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 401 | self.incoming_queues[response.src].put(response) |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 402 | |
| 403 | def _make_ping_frame(self, mac_address): |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 404 | # Create a json packet |
| 405 | json_operation_str = '{\"operation\":\"version\"}' |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 406 | frame = Ether(dst=mac_address)/Dot1Q(vlan=TIBIT_MGMT_VLAN, prio=TIBIT_MGMT_PRIORITY)/TBJSON(data='json %s' % json_operation_str) |
Zsolt Haraszti | 89a2730 | 2016-12-08 16:53:06 -0800 | [diff] [blame] | 407 | return str(frame) |
| 408 | |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 409 | def _make_links_frame(self, mac_address): |
| 410 | # Create a json packet |
| 411 | json_operation_str = '{\"operation\":\"links\"}' |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 412 | frame = Ether(dst=mac_address)/Dot1Q(vlan=TIBIT_MGMT_VLAN, prio=TIBIT_MGMT_PRIORITY)/TBJSON(data='json %s' % json_operation_str) |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 413 | return str(frame) |
| 414 | |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 415 | def abandon_device(self, device): |
| 416 | raise NotImplementedError(0 |
| 417 | ) |
| 418 | def deactivate_device(self, device): |
| 419 | raise NotImplementedError() |
| 420 | |
| 421 | def update_flows_bulk(self, device, flows, groups): |
Nathan Knuth | e69ceb1 | 2017-01-04 21:13:39 -0800 | [diff] [blame] | 422 | log.info('########################################') |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 423 | log.info('bulk-flow-update', device_id=device.id, |
| 424 | flows=flows, groups=groups) |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 425 | assert len(groups.items) == 0, "Cannot yet deal with groups" |
| 426 | |
Nathan Knuth | 5f4163e | 2017-01-11 18:21:10 -0600 | [diff] [blame] | 427 | ONU_VID_208=0xd0 |
| 428 | |
Nathan Knuth | d390ceb | 2017-01-07 15:38:58 -0800 | [diff] [blame] | 429 | Clause = {v: k for k, v in ClauseSubtypeEnum.iteritems()} |
| 430 | Operator = {v: k for k, v in RuleOperatorEnum.iteritems()} |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 431 | |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 432 | for flow in flows.items: |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 433 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 434 | try: |
| 435 | in_port = get_in_port(flow) |
| 436 | assert in_port is not None |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 437 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 438 | precedence = 255 - min(flow.priority / 256, 255) |
Nathan Knuth | e69ceb1 | 2017-01-04 21:13:39 -0800 | [diff] [blame] | 439 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 440 | if in_port == 2: |
| 441 | log.info('#### Downstream Rule ####') |
| 442 | dn_req = NetworkToNetworkPortObject() |
| 443 | dn_req /= PortIngressRuleHeader(precedence=precedence) |
Nathan Knuth | e69ceb1 | 2017-01-04 21:13:39 -0800 | [diff] [blame] | 444 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 445 | for field in get_ofb_fields(flow): |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 446 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 447 | if field.type == ETH_TYPE: |
| 448 | _type = field.eth_type |
| 449 | log.info('#### field.type == ETH_TYPE ####') |
| 450 | dn_req /= PortIngressRuleClauseMatchLength02( |
| 451 | fieldcode=Clause['L2 Type/Len'], |
| 452 | operator=Operator['=='], |
| 453 | match=_type) |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 454 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 455 | elif field.type == IP_PROTO: |
| 456 | _proto = field.ip_proto |
| 457 | log.info('#### field.type == IP_PROTO ####') |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 458 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 459 | elif field.type == IN_PORT: |
| 460 | _port = field.port |
| 461 | log.info('#### field.type == IN_PORT ####', port=_port) |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 462 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 463 | elif field.type == VLAN_VID: |
| 464 | _vlan_vid = field.vlan_vid & 0xfff |
| 465 | log.info('#### field.type == VLAN_VID ####', vlan=_vlan_vid) |
| 466 | dn_req /= PortIngressRuleClauseMatchLength02(fieldcode=Clause['C-VLAN Tag'], fieldinstance=0, |
| 467 | operator=Operator['=='], match=_vlan_vid) |
| 468 | if (_vlan_vid != 140): |
| 469 | dn_req /= PortIngressRuleClauseMatchLength02(fieldcode=Clause['C-VLAN Tag'], fieldinstance=1, |
| 470 | operator=Operator['=='], match=ONU_VID_208) |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 471 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 472 | elif field.type == VLAN_PCP: |
| 473 | _vlan_pcp = field.vlan_pcp |
| 474 | log.info('#### field.type == VLAN_PCP ####', pcp=_vlan_pcp) |
Zsolt Haraszti | 85f1285 | 2016-12-24 08:30:58 -0800 | [diff] [blame] | 475 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 476 | elif field.type == UDP_DST: |
| 477 | _udp_dst = field.udp_dst |
| 478 | log.info('#### field.type == UDP_DST ####') |
Zsolt Haraszti | 6a5107c | 2017-01-09 23:42:41 -0800 | [diff] [blame] | 479 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 480 | elif field.type == UDP_SRC: |
| 481 | _udp_src = field.udp_src |
| 482 | log.info('#### field.type == UDP_SRC ####') |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 483 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 484 | elif field.type == IPV4_DST: |
| 485 | _ipv4_dst = field.ipv4_dst |
| 486 | log.info('#### field.type == IPV4_DST ####') |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 487 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 488 | elif field.type == METADATA: |
| 489 | log.info('#### field.type == METADATA ####') |
| 490 | pass |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 491 | |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 492 | else: |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 493 | raise NotImplementedError('field.type={}'.format( |
| 494 | field.type)) |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 495 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 496 | for action in get_actions(flow): |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 497 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 498 | if action.type == OUTPUT: |
| 499 | log.info('#### action.type == OUTPUT ####') |
| 500 | dn_req /= PortIngressRuleResultForward() |
| 501 | serial = ONU_VID_208 - 200 |
| 502 | link = (0xe222 << 16) | (serial << 8) |
| 503 | dn_req /= PortIngressRuleResultOLTQueue(unicastvssn="TBIT", |
| 504 | unicastlink=link) |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 505 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 506 | elif action.type == POP_VLAN: |
| 507 | log.info('#### action.type == POP_VLAN ####') |
| 508 | dn_req /= PortIngressRuleResultDelete(fieldcode=Clause['S-VLAN Tag']) |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 509 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 510 | elif action.type == PUSH_VLAN: |
| 511 | log.info('#### action.type == PUSH_VLAN ####') |
| 512 | if action.push.ethertype != 0x8100: |
| 513 | log.error('unhandled-tpid', |
| 514 | ethertype=action.push.ethertype) |
| 515 | dn_req /= PortIngressRuleResultInsert(fieldcode=Clause['C-VLAN Tag']) |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 516 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 517 | elif action.type == SET_FIELD: |
| 518 | log.info('#### action.type == SET_FIELD ####') |
| 519 | assert (action.set_field.field.oxm_class == |
| 520 | ofp.OFPXMC_OPENFLOW_BASIC) |
| 521 | field = action.set_field.field.ofb_field |
| 522 | if field.type == VLAN_VID: |
| 523 | dn_req /= PortIngressRuleResultSet( |
| 524 | fieldcode=Clause['C-VLAN Tag'], value=field.vlan_vid & 0xfff) |
| 525 | else: |
| 526 | log.error('unsupported-action-set-field-type', |
| 527 | field_type=field.type) |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 528 | else: |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 529 | log.error('UNSUPPORTED-ACTION-TYPE', |
| 530 | action_type=action.type) |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 531 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 532 | dn_req /= PortIngressRuleTerminator() |
| 533 | dn_req /= AddPortIngressRule() |
| 534 | |
| 535 | msg = ( |
| 536 | Ether(dst=device.mac_address) / |
| 537 | Dot1Q(vlan=TIBIT_MGMT_VLAN, prio=TIBIT_MGMT_PRIORITY) / |
| 538 | EOAMPayload( |
| 539 | body=CablelabsOUI() / DPoEOpcode_SetRequest() / dn_req) |
| 540 | ) |
| 541 | |
| 542 | self.io_port.send(str(msg)) |
| 543 | |
| 544 | elif in_port == 1: |
| 545 | # Upstream rule |
| 546 | log.info('#### Upstream Rule ####') |
| 547 | |
| 548 | field_match_vlan_upstream_with_link = False |
| 549 | up_req_link = PortIngressRuleHeader(precedence=precedence) |
| 550 | |
| 551 | up_req_pon = PonPortObject() |
| 552 | up_req_pon /= PortIngressRuleHeader(precedence=precedence) |
| 553 | |
| 554 | for field in get_ofb_fields(flow): |
| 555 | |
| 556 | if field.type == ETH_TYPE: |
| 557 | _type = field.eth_type |
| 558 | log.info('#### field.type == ETH_TYPE ####', in_port=in_port, |
| 559 | match=_type) |
| 560 | up_req_pon /= PortIngressRuleClauseMatchLength02( |
| 561 | fieldcode=Clause['L2 Type/Len'], |
| 562 | operator=Operator['=='], |
| 563 | match=_type) |
| 564 | |
| 565 | up_req_link /= PortIngressRuleClauseMatchLength02( |
| 566 | fieldcode=Clause['L2 Type/Len'], |
| 567 | operator=Operator['=='], |
| 568 | match=_type) |
| 569 | |
| 570 | elif field.type == IP_PROTO: |
| 571 | _proto = field.ip_proto |
| 572 | log.info('#### field.type == IP_PROTO ####', in_port=in_port, |
| 573 | ip_proto=_proto) |
| 574 | |
| 575 | up_req_pon /= PortIngressRuleClauseMatchLength01( |
| 576 | fieldcode=Clause['IPv4/IPv6 Protocol Type'], |
| 577 | operator=Operator['=='], match=_proto) |
| 578 | |
| 579 | up_req_link /= PortIngressRuleClauseMatchLength01( |
| 580 | fieldcode=Clause['IPv4/IPv6 Protocol Type'], |
| 581 | operator=Operator['=='], match=_proto) |
| 582 | |
| 583 | elif field.type == IN_PORT: |
| 584 | _port = field.port |
| 585 | log.info('#### field.type == IN_PORT ####') |
| 586 | |
| 587 | elif field.type == VLAN_VID: |
| 588 | _vlan_vid = field.vlan_vid & 0xfff |
| 589 | log.info('#### field.type == VLAN_VID ####') |
| 590 | up_req_pon /= PortIngressRuleClauseMatchLength02( |
| 591 | fieldcode=Clause['C-VLAN Tag'], fieldinstance=0, |
| 592 | operator=Operator['=='], match=_vlan_vid) |
| 593 | |
| 594 | serial = _vlan_vid - 200 |
| 595 | link = (0xe222 << 16) | (serial << 8) |
| 596 | up_req_link /= OLTUnicastLogicalLink(unicastvssn='TBIT', unicastlink=link) |
| 597 | |
| 598 | up_req_link /= PortIngressRuleClauseMatchLength02( |
| 599 | fieldcode=Clause['C-VLAN Tag'], fieldinstance=0, |
| 600 | operator=Operator['=='], match=_vlan_vid) |
| 601 | field_match_vlan_upstream_with_link = True |
| 602 | |
| 603 | |
| 604 | elif field.type == VLAN_PCP: |
| 605 | _vlan_pcp = field.vlan_pcp |
| 606 | log.info('#### field.type == VLAN_PCP ####') |
| 607 | |
| 608 | elif field.type == UDP_DST: |
| 609 | _udp_dst = field.udp_dst |
| 610 | log.info('#### field.type == UDP_DST ####') |
| 611 | up_req_pon /= (PortIngressRuleClauseMatchLength02(fieldcode=Clause['TCP/UDP source port'], |
| 612 | operator=Operator['=='], match=0x0044)/ |
| 613 | PortIngressRuleClauseMatchLength02(fieldcode=Clause['TCP/UDP destination port'], |
| 614 | operator=Operator['=='], match=0x0043)) |
| 615 | |
| 616 | elif field.type == UDP_SRC: |
| 617 | _udp_src = field.udp_src |
| 618 | log.info('#### field.type == UDP_SRC ####') |
| 619 | |
| 620 | else: |
| 621 | raise NotImplementedError('field.type={}'.format( |
| 622 | field.type)) |
| 623 | |
| 624 | for action in get_actions(flow): |
| 625 | |
| 626 | if action.type == OUTPUT: |
| 627 | log.info('#### action.type == OUTPUT ####') |
| 628 | up_req_pon /= PortIngressRuleResultForward() |
| 629 | up_req_link /= PortIngressRuleResultForward() |
| 630 | |
| 631 | elif action.type == POP_VLAN: |
| 632 | log.info('#### action.type == POP_VLAN ####') |
| 633 | |
| 634 | elif action.type == PUSH_VLAN: |
| 635 | log.info('#### action.type == PUSH_VLAN ####') |
| 636 | if action.push.ethertype != 0x8100: |
| 637 | log.error('unhandled-ether-type', |
| 638 | ethertype=action.push.ethertype) |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 639 | if field_match_vlan_upstream_with_link == True: |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 640 | up_req_link /= PortIngressRuleResultInsert(fieldcode=Clause['C-VLAN Tag'], |
| 641 | fieldinstance=1) |
| 642 | else: |
| 643 | up_req_pon /= PortIngressRuleResultInsert(fieldcode=Clause['C-VLAN Tag'], |
| 644 | fieldinstance=0) |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 645 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 646 | elif action.type == SET_FIELD: |
| 647 | log.info('#### action.type == SET_FIELD ####') |
| 648 | assert (action.set_field.field.oxm_class == |
| 649 | ofp.OFPXMC_OPENFLOW_BASIC) |
| 650 | field = action.set_field.field.ofb_field |
| 651 | if field.type == VLAN_VID: |
| 652 | if field_match_vlan_upstream_with_link == True: |
| 653 | up_req_link /=(PortIngressRuleResultCopy(fieldcode=Clause['C-VLAN Tag'])/ |
| 654 | PortIngressRuleResultReplace(fieldcode=Clause['C-VLAN Tag'])) |
| 655 | |
| 656 | up_req_pon /= PortIngressRuleResultSet( |
| 657 | fieldcode=Clause['C-VLAN Tag'], value=field.vlan_vid & 0xfff) |
| 658 | up_req_link /= PortIngressRuleResultSet( |
| 659 | fieldcode=Clause['C-VLAN Tag'], value=field.vlan_vid & 0xfff) |
| 660 | else: |
| 661 | log.error('unsupported-action-set-field-type', |
| 662 | field_type=field.type) |
| 663 | |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 664 | else: |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 665 | log.error('UNSUPPORTED-ACTION-TYPE', |
| 666 | action_type=action.type) |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 667 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 668 | if (field_match_vlan_upstream_with_link == True): |
| 669 | up_req = up_req_link |
| 670 | up_req.show() |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 671 | else: |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 672 | up_req = up_req_pon |
Zsolt Haraszti | 8017520 | 2016-12-24 00:17:51 -0800 | [diff] [blame] | 673 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 674 | up_req /= PortIngressRuleTerminator() |
| 675 | up_req /= AddPortIngressRule() |
| 676 | |
| 677 | msg = ( |
| 678 | Ether(dst=device.mac_address) / |
| 679 | Dot1Q(vlan=TIBIT_MGMT_VLAN, prio=TIBIT_MGMT_PRIORITY) / |
| 680 | EOAMPayload( |
| 681 | body=CablelabsOUI() / DPoEOpcode_SetRequest() / up_req) |
| 682 | ) |
| 683 | |
| 684 | self.io_port.send(str(msg)) |
| 685 | |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 686 | else: |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 687 | raise Exception('Port should be 1 or 2 by our convention') |
Nathan Knuth | d8285e6 | 2017-01-11 14:18:43 -0600 | [diff] [blame] | 688 | |
Nathan Knuth | 2976a3f | 2017-01-11 22:47:26 -0800 | [diff] [blame^] | 689 | except Exception, e: |
| 690 | log.exception('failed-to-install-flow', e=e, flow=flow) |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 691 | |
| 692 | def update_flows_incrementally(self, device, flow_changes, group_changes): |
| 693 | raise NotImplementedError() |
| 694 | |
| 695 | def send_proxied_message(self, proxy_address, msg): |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 696 | log.info('send-proxied-message', proxy_address=proxy_address) |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 697 | device = self.adapter_agent.get_device(proxy_address.device_id) |
Nathan Knuth | e69ceb1 | 2017-01-04 21:13:39 -0800 | [diff] [blame] | 698 | frame = Ether(dst=device.mac_address) / \ |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 699 | Dot1Q(vlan=TIBIT_MGMT_VLAN, prio=TIBIT_MGMT_PRIORITY) / \ |
| 700 | Dot1Q(vlan=proxy_address.channel_id, prio=TIBIT_MGMT_PRIORITY) / \ |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 701 | msg |
Nathan Knuth | 6e57f33 | 2016-12-22 15:49:20 -0800 | [diff] [blame] | 702 | |
Zsolt Haraszti | 348d193 | 2016-12-10 01:10:07 -0800 | [diff] [blame] | 703 | self.io_port.send(str(frame)) |
Zsolt Haraszti | ed09160 | 2016-12-08 13:36:38 -0800 | [diff] [blame] | 704 | |
| 705 | def receive_proxied_message(self, proxy_address, msg): |
| 706 | raise NotImplementedError() |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 707 | |
| 708 | def receive_packet_out(self, logical_device_id, egress_port_no, msg): |
| 709 | log.info('packet-out', logical_device_id=logical_device_id, |
| 710 | egress_port_no=egress_port_no, msg_len=len(msg)) |
Nathan Knuth | fe2b2e0 | 2017-01-06 07:29:02 -0800 | [diff] [blame] | 711 | |
| 712 | dev_id, logical_dev_id = self.vlan_to_device_ids[egress_port_no] |
| 713 | if logical_dev_id != logical_device_id: |
| 714 | raise Exception('Internal table mismatch') |
| 715 | |
| 716 | tmp = Ether(msg) |
| 717 | |
| 718 | frame = Ether(dst=tmp.dst, src=tmp.src) / \ |
| 719 | Dot1Q(vlan=TIBIT_PACKET_OUT_VLAN) / \ |
| 720 | Dot1Q(vlan=egress_port_no) / \ |
| 721 | tmp.payload |
| 722 | |
| 723 | self.io_port.send(str(frame)) |