blob: 2ac33bfc955faaf0f73a9ae9884cd152ec7d1bbe [file] [log] [blame]
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001#
Zsolt Haraszti3eb27a52017-01-03 21:56:48 -08002# Copyright 2017 the original author or authors.
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08003#
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"""
Steve Crooks3c2c7582017-01-10 15:02:26 -060018Broadcom OLT/ONU adapter.
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080019"""
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080020
Steve Crooks3c2c7582017-01-10 15:02:26 -060021from uuid import uuid4
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080022import structlog
Peter Shafikd7f33772017-05-17 13:56:34 -040023from twisted.internet import reactor, task
Steve Crooks3c2c7582017-01-10 15:02:26 -060024from twisted.internet.defer import DeferredQueue, inlineCallbacks
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080025from zope.interface import implementer
26
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080027from voltha.adapters.interface import IAdapterInterface
28from voltha.core.logical_device_agent import mac_str_to_tuple
Steve Crooksf248e182017-02-07 10:50:24 -050029import voltha.core.flow_decomposer as fd
Steve Crooks3c2c7582017-01-10 15:02:26 -060030from voltha.protos import third_party
31from voltha.protos.adapter_pb2 import Adapter
32from voltha.protos.adapter_pb2 import AdapterConfig
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080033from voltha.protos.common_pb2 import LogLevel, OperStatus, ConnectStatus, \
34 AdminState
ggowdru236bd952017-06-20 20:32:55 -070035from voltha.protos.device_pb2 import DeviceType, DeviceTypes, Port, Image
Steve Crooks3c2c7582017-01-10 15:02:26 -060036from voltha.protos.health_pb2 import HealthStatus
37from voltha.protos.logical_device_pb2 import LogicalPort
rshettyf4bf19e2017-09-19 01:28:27 +053038from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, OFPPF_1GB_FD, OFPPS_LINK_DOWN
Steve Crooksf248e182017-02-07 10:50:24 -050039from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port
rshetty1cc73982017-09-02 03:31:12 +053040from voltha.protos.bbf_fiber_base_pb2 import VEnetConfig
rshettyf4bf19e2017-09-19 01:28:27 +053041from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import \
42 TrafficDescriptorProfileData
43from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData
44from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData
rshetty1cc73982017-09-02 03:31:12 +053045
Steve Crooks3c2c7582017-01-10 15:02:26 -060046from common.frameio.frameio import hexify
47from voltha.extensions.omci.omci import *
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080048
Steve Crooks3c2c7582017-01-10 15:02:26 -060049_ = third_party
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080050log = structlog.get_logger()
51
52
rshettyf4bf19e2017-09-19 01:28:27 +053053BRDCM_DEFAULT_VLAN = 4091
54
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080055@implementer(IAdapterInterface)
56class BroadcomOnuAdapter(object):
57
58 name = 'broadcom_onu'
59
60 supported_device_types = [
61 DeviceType(
Steve Crooks3c2c7582017-01-10 15:02:26 -060062 id=name,
rshettyc26a3c32017-07-27 11:06:38 +053063 vendor_id='BRCM',
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080064 adapter=name,
65 accepts_bulk_flow_update=True
66 )
67 ]
68
69 def __init__(self, adapter_agent, config):
70 self.adapter_agent = adapter_agent
71 self.config = config
72 self.descriptor = Adapter(
73 id=self.name,
74 vendor='Voltha project',
Steve Crooks3c2c7582017-01-10 15:02:26 -060075 version='0.4',
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080076 config=AdapterConfig(log_level=LogLevel.INFO)
77 )
Steve Crooks3c2c7582017-01-10 15:02:26 -060078 self.devices_handlers = dict() # device_id -> BroadcomOnuHandler()
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080079
Peter Shafik9107f2e2017-05-02 15:54:39 -040080 # register for adapter messages
81 self.adapter_agent.register_for_inter_adapter_messages()
82
Zsolt Haraszticc153aa2016-12-14 02:28:59 -080083 def start(self):
84 log.debug('starting')
85 log.info('started')
86
87 def stop(self):
88 log.debug('stopping')
89 log.info('stopped')
90
91 def adapter_descriptor(self):
92 return self.descriptor
93
94 def device_types(self):
95 return DeviceTypes(items=self.supported_device_types)
96
97 def health(self):
98 return HealthStatus(state=HealthStatus.HealthState.HEALTHY)
99
100 def change_master_state(self, master):
101 raise NotImplementedError()
102
103 def adopt_device(self, device):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600104 log.info('adopt_device', device_id=device.id)
rshettyf4bf19e2017-09-19 01:28:27 +0530105 self.devices_handlers[device.id] = BroadcomOnuHandler(self, device.id)
106 reactor.callLater(0, self.devices_handlers[device.id].activate, device)
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800107 return device
108
khenaidoo032d3302017-06-09 14:50:04 -0400109 def reconcile_device(self, device):
sathishgc2ef54a2017-11-03 18:32:11 +0530110 log.info('reconcile-device', device_id=device.id)
111 self.devices_handlers[device.id] = BroadcomOnuHandler(self, device.id)
112 reactor.callLater(0, self.devices_handlers[device.id].reconcile, device)
khenaidoo032d3302017-06-09 14:50:04 -0400113
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800114 def abandon_device(self, device):
115 raise NotImplementedError()
116
Khen Nursimulud068d812017-03-06 11:44:18 -0500117 def disable_device(self, device):
118 raise NotImplementedError()
119
120 def reenable_device(self, device):
121 raise NotImplementedError()
122
123 def reboot_device(self, device):
124 raise NotImplementedError()
125
Lydia Fang01f2e852017-06-28 17:24:58 -0700126 def download_image(self, device, request):
127 raise NotImplementedError()
128
129 def get_image_download_status(self, device, request):
130 raise NotImplementedError()
131
132 def cancel_image_download(self, device, request):
133 raise NotImplementedError()
134
135 def activate_image_update(self, device, request):
136 raise NotImplementedError()
137
138 def revert_image_update(self, device, request):
139 raise NotImplementedError()
140
sathishg5ae86222017-06-28 15:16:29 +0530141 def self_test_device(self, device):
142 """
143 This is called to Self a device based on a NBI call.
144 :param device: A Voltha.Device object.
145 :return: Will return result of self test
146 """
147 log.info('self-test-device', device=device.id)
148 raise NotImplementedError()
149
Khen Nursimulud068d812017-03-06 11:44:18 -0500150 def delete_device(self, device):
151 raise NotImplementedError()
152
153 def get_device_details(self, device):
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800154 raise NotImplementedError()
155
Sergio Slobodrianec864c62017-03-09 11:41:43 -0500156 def update_pm_config(self, device, pm_configs):
157 raise NotImplementedError()
158
Steve Crooks3c2c7582017-01-10 15:02:26 -0600159 def update_flows_bulk(self, device, flows, groups):
rshettyf4bf19e2017-09-19 01:28:27 +0530160 '''
Steve Crooks3c2c7582017-01-10 15:02:26 -0600161 log.info('bulk-flow-update', device_id=device.id,
162 flows=flows, groups=groups)
rshettyf4bf19e2017-09-19 01:28:27 +0530163 '''
Steve Crooks3c2c7582017-01-10 15:02:26 -0600164 assert len(groups.items) == 0
rshettyf4bf19e2017-09-19 01:28:27 +0530165 handler = self.devices_handlers[device.id]
Steve Crooksf248e182017-02-07 10:50:24 -0500166 return handler.update_flow_table(device, flows.items)
Steve Crooks3c2c7582017-01-10 15:02:26 -0600167
168 def update_flows_incrementally(self, device, flow_changes, group_changes):
169 raise NotImplementedError()
170
171 def send_proxied_message(self, proxy_address, msg):
172 log.info('send-proxied-message', proxy_address=proxy_address, msg=msg)
173
174 def receive_proxied_message(self, proxy_address, msg):
175 log.info('receive-proxied-message', proxy_address=proxy_address,
176 device_id=proxy_address.device_id, msg=hexify(msg))
rshettyf4bf19e2017-09-19 01:28:27 +0530177 # Device_id from the proxy_address is the olt device id. We need to
178 # get the onu device id using the port number in the proxy_address
179 device = self.adapter_agent. \
180 get_child_device_with_proxy_address(proxy_address)
181 if device:
182 handler = self.devices_handlers[device.id]
183 handler.receive_message(msg)
Steve Crooks3c2c7582017-01-10 15:02:26 -0600184
185 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
186 log.info('packet-out', logical_device_id=logical_device_id,
187 egress_port_no=egress_port_no, msg_len=len(msg))
188
Peter Shafik9107f2e2017-05-02 15:54:39 -0400189 def receive_inter_adapter_message(self, msg):
190 log.info('receive_inter_adapter_message', msg=msg)
Peter Shafikd7f33772017-05-17 13:56:34 -0400191 proxy_address = msg['proxy_address']
192 assert proxy_address is not None
rshettyf4bf19e2017-09-19 01:28:27 +0530193 # Device_id from the proxy_address is the olt device id. We need to
194 # get the onu device id using the port number in the proxy_address
195 device = self.adapter_agent. \
196 get_child_device_with_proxy_address(proxy_address)
197 if device:
198 handler = self.devices_handlers[device.id]
199 handler.event_messages.put(msg)
Peter Shafik9107f2e2017-05-02 15:54:39 -0400200
Nikolay Titov89004ec2017-06-19 18:22:42 -0400201 def create_interface(self, device, data):
rshettyc26a3c32017-07-27 11:06:38 +0530202 log.info('create-interface', device_id=device.id)
rshettyf4bf19e2017-09-19 01:28:27 +0530203 if device.id in self.devices_handlers:
204 handler = self.devices_handlers[device.id]
rshettyc26a3c32017-07-27 11:06:38 +0530205 if handler is not None:
206 handler.create_interface(data)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400207
208 def update_interface(self, device, data):
rshettyc26a3c32017-07-27 11:06:38 +0530209 log.info('update-interface', device_id=device.id)
rshettyf4bf19e2017-09-19 01:28:27 +0530210 if device.id in self.devices_handlers:
211 handler = self.devices_handlers[device.id]
rshettyc26a3c32017-07-27 11:06:38 +0530212 if handler is not None:
213 handler.update_interface(data)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400214
215 def remove_interface(self, device, data):
rshettyc26a3c32017-07-27 11:06:38 +0530216 log.info('remove-interface', device_id=device.id)
rshettyf4bf19e2017-09-19 01:28:27 +0530217 if device.id in self.devices_handlers:
218 handler = self.devices_handlers[device.id]
rshettyc26a3c32017-07-27 11:06:38 +0530219 if handler is not None:
220 handler.remove_interface(data)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400221
222 def receive_onu_detect_state(self, device_id, state):
223 raise NotImplementedError()
224
Nikolay Titov176f1db2017-08-10 12:38:43 -0400225 def create_tcont(self, device, tcont_data, traffic_descriptor_data):
rshettyf4bf19e2017-09-19 01:28:27 +0530226 log.info('create-tcont', device_id=device.id)
227 if device.id in self.devices_handlers:
228 handler = self.devices_handlers[device.id]
229 if handler is not None:
230 handler.create_tcont(tcont_data, traffic_descriptor_data)
Nikolay Titov176f1db2017-08-10 12:38:43 -0400231
232 def update_tcont(self, device, tcont_data, traffic_descriptor_data):
233 raise NotImplementedError()
234
235 def remove_tcont(self, device, tcont_data, traffic_descriptor_data):
236 raise NotImplementedError()
237
238 def create_gemport(self, device, data):
rshettyf4bf19e2017-09-19 01:28:27 +0530239 log.info('create-gemport', device_id=device.id)
240 if device.id in self.devices_handlers:
241 handler = self.devices_handlers[device.id]
242 if handler is not None:
243 handler.create_gemport(data)
Nikolay Titov176f1db2017-08-10 12:38:43 -0400244
245 def update_gemport(self, device, data):
246 raise NotImplementedError()
247
248 def remove_gemport(self, device, data):
249 raise NotImplementedError()
250
251 def create_multicast_gemport(self, device, data):
rshettyf4bf19e2017-09-19 01:28:27 +0530252 log.info('create-multicast-gemport', device_id=device.id)
253 if device.id in self.devices_handlers:
254 handler = self.devices_handlers[device.id]
255 if handler is not None:
256 handler.create_multicast_gemport(data)
Nikolay Titov176f1db2017-08-10 12:38:43 -0400257
258 def update_multicast_gemport(self, device, data):
259 raise NotImplementedError()
260
261 def remove_multicast_gemport(self, device, data):
262 raise NotImplementedError()
263
264 def create_multicast_distribution_set(self, device, data):
265 raise NotImplementedError()
266
267 def update_multicast_distribution_set(self, device, data):
268 raise NotImplementedError()
269
270 def remove_multicast_distribution_set(self, device, data):
271 raise NotImplementedError()
272
273 def suppress_alarm(self, filter):
274 raise NotImplementedError()
275
Stephane Barbarie980a0912017-05-11 11:27:06 -0400276 def unsuppress_alarm(self, filter):
277 raise NotImplementedError()
Steve Crooks3c2c7582017-01-10 15:02:26 -0600278
279class BroadcomOnuHandler(object):
280
281 def __init__(self, adapter, device_id):
282 self.adapter = adapter
283 self.adapter_agent = adapter.adapter_agent
284 self.device_id = device_id
285 self.log = structlog.get_logger(device_id=device_id)
286 self.incoming_messages = DeferredQueue()
Peter Shafikd7f33772017-05-17 13:56:34 -0400287 self.event_messages = DeferredQueue()
Steve Crooks3c2c7582017-01-10 15:02:26 -0600288 self.proxy_address = None
289 self.tx_id = 0
290
Peter Shafikd7f33772017-05-17 13:56:34 -0400291 # Need to query ONU for number of supported uni ports
292 # For now, temporarily set number of ports to 1 - port #2
293 self.uni_ports = (2,)
294
295 # Handle received ONU event messages
296 reactor.callLater(0, self.handle_onu_events)
297
Steve Crooks3c2c7582017-01-10 15:02:26 -0600298 def receive_message(self, msg):
299 self.incoming_messages.put(msg)
300
Peter Shafikd7f33772017-05-17 13:56:34 -0400301 @inlineCallbacks
302 def handle_onu_events(self):
303 event_msg = yield self.event_messages.get()
304
305 if event_msg['event'] == 'activation-completed':
306
307 if event_msg['event_data']['activation_successful'] == True:
308 for uni in self.uni_ports:
309 port_no = self.proxy_address.channel_id + uni
310 reactor.callLater(1,
311 self.message_exchange,
312 self.proxy_address.onu_id,
313 self.proxy_address.onu_session_id,
314 port_no)
315
316 device = self.adapter_agent.get_device(self.device_id)
317 device.oper_status = OperStatus.ACTIVE
318 self.adapter_agent.update_device(device)
319
320 else:
321 device = self.adapter_agent.get_device(self.device_id)
322 device.oper_status = OperStatus.FAILED
323 self.adapter_agent.update_device(device)
324
325 elif event_msg['event'] == 'deactivation-completed':
326 device = self.adapter_agent.get_device(self.device_id)
327 device.oper_status = OperStatus.DISCOVERED
328 self.adapter_agent.update_device(device)
329
330 elif event_msg['event'] == 'ranging-completed':
331
332 if event_msg['event_data']['ranging_successful'] == True:
333 device = self.adapter_agent.get_device(self.device_id)
334 device.oper_status = OperStatus.ACTIVATING
335 self.adapter_agent.update_device(device)
336
337 else:
338 device = self.adapter_agent.get_device(self.device_id)
339 device.oper_status = OperStatus.FAILED
340 self.adapter_agent.update_device(device)
341
342 # Handle next event
343 reactor.callLater(0, self.handle_onu_events)
344
345
Steve Crooks3c2c7582017-01-10 15:02:26 -0600346 def activate(self, device):
347 self.log.info('activating')
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800348
349 # first we verify that we got parent reference and proxy info
350 assert device.parent_id
351 assert device.proxy_address.device_id
Steve Crooks9b160d72017-03-31 10:48:29 -0500352 #assert device.proxy_address.channel_id # c-vid
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800353
Steve Crooks3c2c7582017-01-10 15:02:26 -0600354 # register for proxied messages right away
355 self.proxy_address = device.proxy_address
356 self.adapter_agent.register_for_proxied_messages(device.proxy_address)
357
Peter Shafik9107f2e2017-05-02 15:54:39 -0400358
Steve Crooks3c2c7582017-01-10 15:02:26 -0600359 # populate device info
360 device.root = True
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800361 device.vendor = 'Broadcom'
Steve Crooks9e85ce82017-03-20 12:00:53 -0400362 device.model = 'n/a'
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800363 device.hardware_version = 'to be filled'
364 device.firmware_version = 'to be filled'
ggowdru236bd952017-06-20 20:32:55 -0700365 device.images.image.extend([
366 Image(version="to be filled")
367 ])
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800368 device.connect_status = ConnectStatus.REACHABLE
369 self.adapter_agent.update_device(device)
370
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800371 self.adapter_agent.add_port(device.id, Port(
Steve Crooks9b160d72017-03-31 10:48:29 -0500372 port_no=100,
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800373 label='PON port',
374 type=Port.PON_ONU,
375 admin_state=AdminState.ENABLED,
376 oper_status=OperStatus.ACTIVE,
377 peers=[
378 Port.PeerPort(
379 device_id=device.parent_id,
380 port_no=device.parent_port_no
381 )
382 ]
383 ))
384
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800385 parent_device = self.adapter_agent.get_device(device.parent_id)
386 logical_device_id = parent_device.parent_id
387 assert logical_device_id
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800388 device = self.adapter_agent.get_device(device.id)
Peter Shafikd7f33772017-05-17 13:56:34 -0400389 device.oper_status = OperStatus.DISCOVERED
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800390 self.adapter_agent.update_device(device)
391
sathishgc2ef54a2017-11-03 18:32:11 +0530392 def reconcile(self, device):
393
394 log.info('reconciling-broadcom-onu-device-starts')
395
396 # first we verify that we got parent reference and proxy info
397 assert device.parent_id
398 assert device.proxy_address.device_id
399
400 # register for proxied messages right away
401 self.proxy_address = device.proxy_address
402 self.adapter_agent.register_for_proxied_messages(device.proxy_address)
403
404 # TODO: Query ONU current status after reconcile and update.
405 # To be addressed in future commits.
406
407 log.info('reconciling-broadcom-onu-device-ends')
408
409
Steve Crooks3c2c7582017-01-10 15:02:26 -0600410 @inlineCallbacks
Steve Crooksf248e182017-02-07 10:50:24 -0500411 def update_flow_table(self, device, flows):
412 #
413 # We need to proxy through the OLT to get to the ONU
414 # Configuration from here should be using OMCI
415 #
rshettyf4bf19e2017-09-19 01:28:27 +0530416 #self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800417
Steve Crooksf248e182017-02-07 10:50:24 -0500418 def is_downstream(port):
Steve Crooks9b160d72017-03-31 10:48:29 -0500419 return port == 100 # Need a better way
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800420
Steve Crooksf248e182017-02-07 10:50:24 -0500421 def is_upstream(port):
422 return not is_downstream(port)
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800423
Steve Crooksf248e182017-02-07 10:50:24 -0500424 for flow in flows:
Steve Crooks9b160d72017-03-31 10:48:29 -0500425 _type = None
426 _port = None
427 _vlan_vid = None
428 _udp_dst = None
429 _udp_src = None
430 _ipv4_dst = None
431 _ipv4_src = None
432 _metadata = None
433 _output = None
434 _push_tpid = None
435 _field = None
436 _set_vlan_vid = None
rshettyf4bf19e2017-09-19 01:28:27 +0530437 self.log.info('bulk-flow-update', device_id=device.id, flow=flow)
Steve Crooksf248e182017-02-07 10:50:24 -0500438 try:
439 _in_port = fd.get_in_port(flow)
440 assert _in_port is not None
Steve Crooks3c2c7582017-01-10 15:02:26 -0600441
Steve Crooksf248e182017-02-07 10:50:24 -0500442 if is_downstream(_in_port):
443 self.log.info('downstream-flow')
444 elif is_upstream(_in_port):
445 self.log.info('upstream-flow')
446 else:
447 raise Exception('port should be 1 or 2 by our convention')
448
449 _out_port = fd.get_out_port(flow) # may be None
450 self.log.info('out-port', out_port=_out_port)
451
452 for field in fd.get_ofb_fields(flow):
453 if field.type == fd.ETH_TYPE:
454 _type = field.eth_type
455 self.log.info('field-type-eth-type',
456 eth_type=_type)
457
458 elif field.type == fd.IP_PROTO:
459 _proto = field.ip_proto
460 self.log.info('field-type-ip-proto',
461 ip_proto=_proto)
462
463 elif field.type == fd.IN_PORT:
464 _port = field.port
465 self.log.info('field-type-in-port',
466 in_port=_port)
467
468 elif field.type == fd.VLAN_VID:
469 _vlan_vid = field.vlan_vid & 0xfff
470 self.log.info('field-type-vlan-vid',
471 vlan=_vlan_vid)
472
473 elif field.type == fd.VLAN_PCP:
474 _vlan_pcp = field.vlan_pcp
475 self.log.info('field-type-vlan-pcp',
476 pcp=_vlan_pcp)
477
478 elif field.type == fd.UDP_DST:
479 _udp_dst = field.udp_dst
480 self.log.info('field-type-udp-dst',
481 udp_dst=_udp_dst)
482
483 elif field.type == fd.UDP_SRC:
484 _udp_src = field.udp_src
485 self.log.info('field-type-udp-src',
486 udp_src=_udp_src)
487
488 elif field.type == fd.IPV4_DST:
489 _ipv4_dst = field.ipv4_dst
490 self.log.info('field-type-ipv4-dst',
491 ipv4_dst=_ipv4_dst)
492
493 elif field.type == fd.IPV4_SRC:
494 _ipv4_src = field.ipv4_src
495 self.log.info('field-type-ipv4-src',
496 ipv4_dst=_ipv4_src)
497
498 elif field.type == fd.METADATA:
Steve Crooks9b160d72017-03-31 10:48:29 -0500499 _metadata = field.table_metadata
Steve Crooksf248e182017-02-07 10:50:24 -0500500 self.log.info('field-type-metadata',
501 metadata=_metadata)
502
503 else:
504 raise NotImplementedError('field.type={}'.format(
505 field.type))
506
507 for action in fd.get_actions(flow):
508
509 if action.type == fd.OUTPUT:
510 _output = action.output.port
511 self.log.info('action-type-output',
512 output=_output, in_port=_in_port)
513
514 elif action.type == fd.POP_VLAN:
515 self.log.info('action-type-pop-vlan',
516 in_port=_in_port)
517
518 elif action.type == fd.PUSH_VLAN:
519 _push_tpid = action.push.ethertype
520 log.info('action-type-push-vlan',
521 push_tpid=_push_tpid, in_port=_in_port)
522 if action.push.ethertype != 0x8100:
523 self.log.error('unhandled-tpid',
524 ethertype=action.push.ethertype)
525
526 elif action.type == fd.SET_FIELD:
527 _field = action.set_field.field.ofb_field
528 assert (action.set_field.field.oxm_class ==
529 OFPXMC_OPENFLOW_BASIC)
530 self.log.info('action-type-set-field',
531 field=_field, in_port=_in_port)
532 if _field.type == fd.VLAN_VID:
Steve Crooks9b160d72017-03-31 10:48:29 -0500533 _set_vlan_vid = _field.vlan_vid & 0xfff
534 self.log.info('set-field-type-valn-vid', _set_vlan_vid)
Steve Crooksf248e182017-02-07 10:50:24 -0500535 else:
536 self.log.error('unsupported-action-set-field-type',
537 field_type=_field.type)
538 else:
539 log.error('unsupported-action-type',
540 action_type=action.type, in_port=_in_port)
541
542 #
543 # All flows created from ONU adapter should be OMCI based
544 #
rshettyf4bf19e2017-09-19 01:28:27 +0530545 if _vlan_vid == 0 and _set_vlan_vid != None and _set_vlan_vid != 0:
Steve Crooks9b160d72017-03-31 10:48:29 -0500546 # allow priority tagged packets
547 # Set AR - ExtendedVlanTaggingOperationConfigData
548 # 514 - RxVlanTaggingOperationTable - add VLAN <cvid> to priority tagged pkts - c-vid
rshettyf4bf19e2017-09-19 01:28:27 +0530549
550 self.send_delete_vlan_tagging_filter_data(0x2102)
551 yield self.wait_for_response()
552
553 #self.send_set_vlan_tagging_filter_data(0x2102, _set_vlan_vid)
554 self.send_create_vlan_tagging_filter_data(0x2102, _set_vlan_vid)
555 yield self.wait_for_response()
556
557 self.send_set_extended_vlan_tagging_operation_vlan_configuration_data_untagged(0x202, 0x1000, _set_vlan_vid)
558 yield self.wait_for_response()
559
Steve Crooks9b160d72017-03-31 10:48:29 -0500560 self.send_set_extended_vlan_tagging_operation_vlan_configuration_data_single_tag(0x202, 8, 0, 0,
rshettyf4bf19e2017-09-19 01:28:27 +0530561 1, 8, _set_vlan_vid)
Steve Crooks9b160d72017-03-31 10:48:29 -0500562 yield self.wait_for_response()
563
564 # Set AR - ExtendedVlanTaggingOperationConfigData
565 # 514 - RxVlanTaggingOperationTable - add VLAN <cvid> to priority tagged pkts - c-vid
rshettyf4bf19e2017-09-19 01:28:27 +0530566 '''
Steve Crooks9b160d72017-03-31 10:48:29 -0500567 self.send_set_extended_vlan_tagging_operation_vlan_configuration_data_single_tag(0x205, 8, 0, 0,
rshettyf4bf19e2017-09-19 01:28:27 +0530568 1, 8, _set_vlan_vid)
Steve Crooks9b160d72017-03-31 10:48:29 -0500569 yield self.wait_for_response()
rshettyf4bf19e2017-09-19 01:28:27 +0530570 '''
Steve Crooksf248e182017-02-07 10:50:24 -0500571
572 except Exception as e:
573 log.exception('failed-to-install-flow', e=e, flow=flow)
574
Steve Crooks3c2c7582017-01-10 15:02:26 -0600575 def get_tx_id(self):
576 self.tx_id += 1
577 return self.tx_id
578
579 def send_omci_message(self, frame):
580 _frame = hexify(str(frame))
581 self.log.info('send-omci-message-%s' % _frame)
582 device = self.adapter_agent.get_device(self.device_id)
583 try:
584 self.adapter_agent.send_proxied_message(device.proxy_address, _frame)
585 except Exception as e:
586 self.log.info('send-omci-message-exception', exc=str(e))
587
588 def send_get_circuit_pack(self, entity_id=0):
589 frame = OmciFrame(
590 transaction_id=self.get_tx_id(),
591 message_type=OmciGet.message_id,
592 omci_message=OmciGet(
593 entity_class=CircuitPack.class_id,
594 entity_id=entity_id,
595 attributes_mask=CircuitPack.mask_for('vendor_id')
596 )
597 )
598 self.send_omci_message(frame)
599
600 def send_mib_reset(self, entity_id=0):
601 frame = OmciFrame(
602 transaction_id=self.get_tx_id(),
603 message_type=OmciMibReset.message_id,
604 omci_message=OmciMibReset(
605 entity_class=OntData.class_id,
606 entity_id=entity_id
607 )
608 )
609 self.send_omci_message(frame)
610
Steve Crooks9e85ce82017-03-20 12:00:53 -0400611 def send_create_gal_ethernet_profile(self,
612 entity_id,
613 max_gem_payload_size):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600614 frame = OmciFrame(
615 transaction_id=self.get_tx_id(),
616 message_type=OmciCreate.message_id,
617 omci_message=OmciCreate(
618 entity_class=GalEthernetProfile.class_id,
619 entity_id=entity_id,
620 data=dict(
621 max_gem_payload_size=max_gem_payload_size
622 )
623 )
624 )
625 self.send_omci_message(frame)
626
Steve Crooks9e85ce82017-03-20 12:00:53 -0400627 def send_set_tcont(self,
628 entity_id,
629 alloc_id):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600630 data = dict(
631 alloc_id=alloc_id
632 )
633 frame = OmciFrame(
634 transaction_id=self.get_tx_id(),
635 message_type=OmciSet.message_id,
636 omci_message=OmciSet(
637 entity_class=Tcont.class_id,
Steve Crooks9e85ce82017-03-20 12:00:53 -0400638 entity_id=entity_id,
Steve Crooks3c2c7582017-01-10 15:02:26 -0600639 attributes_mask=Tcont.mask_for(*data.keys()),
640 data=data
641 )
642 )
643 self.send_omci_message(frame)
644
Steve Crooks9e85ce82017-03-20 12:00:53 -0400645 def send_create_8021p_mapper_service_profile(self,
646 entity_id):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600647 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400648 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600649 message_type=OmciCreate.message_id,
650 omci_message=OmciCreate(
651 entity_class=Ieee8021pMapperServiceProfile.class_id,
652 entity_id=entity_id,
653 data=dict(
654 tp_pointer=OmciNullPointer,
655 interwork_tp_pointer_for_p_bit_priority_0=OmciNullPointer,
Steve Crooks9b160d72017-03-31 10:48:29 -0500656 interwork_tp_pointer_for_p_bit_priority_1=OmciNullPointer,
657 interwork_tp_pointer_for_p_bit_priority_2=OmciNullPointer,
658 interwork_tp_pointer_for_p_bit_priority_3=OmciNullPointer,
659 interwork_tp_pointer_for_p_bit_priority_4=OmciNullPointer,
660 interwork_tp_pointer_for_p_bit_priority_5=OmciNullPointer,
661 interwork_tp_pointer_for_p_bit_priority_6=OmciNullPointer,
662 interwork_tp_pointer_for_p_bit_priority_7=OmciNullPointer
Steve Crooks3c2c7582017-01-10 15:02:26 -0600663 )
664 )
665 )
666 self.send_omci_message(frame)
667
Steve Crooks9e85ce82017-03-20 12:00:53 -0400668 def send_create_mac_bridge_service_profile(self,
669 entity_id):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600670 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400671 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600672 message_type=OmciCreate.message_id,
673 omci_message=OmciCreate(
674 entity_class=MacBridgeServiceProfile.class_id,
675 entity_id=entity_id,
676 data=dict(
677 spanning_tree_ind=False,
678 learning_ind=True,
679 priority=0x8000,
680 max_age=20 * 256,
681 hello_time=2 * 256,
682 forward_delay=15 * 256,
683 unknown_mac_address_discard=True
684 )
685 )
686 )
687 self.send_omci_message(frame)
688
Steve Crooks9e85ce82017-03-20 12:00:53 -0400689 def send_create_gem_port_network_ctp(self,
690 entity_id,
691 port_id,
692 tcont_id,
693 direction,
694 tm):
695 _directions = {"upstream": 1, "downstream": 2, "bi-directional": 3}
696 if _directions.has_key(direction):
697 _direction = _directions[direction]
698 else:
699 self.log.error('invalid-gem-port-direction', direction=direction)
700 raise ValueError('Invalid GEM port direction: {_dir}'.format(_dir=direction))
701
Steve Crooks3c2c7582017-01-10 15:02:26 -0600702 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400703 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600704 message_type=OmciCreate.message_id,
705 omci_message=OmciCreate(
706 entity_class=GemPortNetworkCtp.class_id,
707 entity_id=entity_id,
708 data=dict(
709 port_id=port_id,
710 tcont_pointer=tcont_id,
Steve Crooks9e85ce82017-03-20 12:00:53 -0400711 direction=_direction,
712 traffic_management_pointer_upstream=tm
Steve Crooks3c2c7582017-01-10 15:02:26 -0600713 )
714 )
715 )
716 self.send_omci_message(frame)
717
Steve Crooks9e85ce82017-03-20 12:00:53 -0400718 def send_create_multicast_gem_interworking_tp(self,
719 entity_id,
720 gem_port_net_ctp_id):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600721 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400722 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600723 message_type=OmciCreate.message_id,
724 omci_message=OmciCreate(
725 entity_class=MulticastGemInterworkingTp.class_id,
726 entity_id=entity_id,
727 data=dict(
728 gem_port_network_ctp_pointer=gem_port_net_ctp_id,
729 interworking_option=0,
Steve Crooks9e85ce82017-03-20 12:00:53 -0400730 service_profile_pointer=0x1
Steve Crooks3c2c7582017-01-10 15:02:26 -0600731 )
732 )
733 )
734 self.send_omci_message(frame)
735
Steve Crooks9e85ce82017-03-20 12:00:53 -0400736 def send_create_gem_inteworking_tp(self,
737 entity_id,
738 gem_port_net_ctp_id,
739 service_profile_id):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600740 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400741 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600742 message_type=OmciCreate.message_id,
743 omci_message=OmciCreate(
744 entity_class=GemInterworkingTp.class_id,
745 entity_id=entity_id,
746 data=dict(
747 gem_port_network_ctp_pointer=gem_port_net_ctp_id,
748 interworking_option=5,
749 service_profile_pointer=service_profile_id,
750 interworking_tp_pointer=0x0,
751 gal_profile_pointer=0x1
752 )
753 )
754 )
755 self.send_omci_message(frame)
756
Steve Crooks9e85ce82017-03-20 12:00:53 -0400757 def send_set_8021p_mapper_service_profile(self,
758 entity_id,
759 interwork_tp_id):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600760 data = dict(
Steve Crooks9b160d72017-03-31 10:48:29 -0500761 interwork_tp_pointer_for_p_bit_priority_0=interwork_tp_id,
762 interwork_tp_pointer_for_p_bit_priority_1=interwork_tp_id,
763 interwork_tp_pointer_for_p_bit_priority_2=interwork_tp_id,
764 interwork_tp_pointer_for_p_bit_priority_3=interwork_tp_id,
765 interwork_tp_pointer_for_p_bit_priority_4=interwork_tp_id,
766 interwork_tp_pointer_for_p_bit_priority_5=interwork_tp_id,
767 interwork_tp_pointer_for_p_bit_priority_6=interwork_tp_id,
768 interwork_tp_pointer_for_p_bit_priority_7=interwork_tp_id
Steve Crooks3c2c7582017-01-10 15:02:26 -0600769 )
770 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400771 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600772 message_type=OmciSet.message_id,
773 omci_message=OmciSet(
774 entity_class=Ieee8021pMapperServiceProfile.class_id,
775 entity_id=entity_id,
776 attributes_mask=Ieee8021pMapperServiceProfile.mask_for(
777 *data.keys()),
778 data=data
779 )
780 )
781 self.send_omci_message(frame)
782
783 def send_create_mac_bridge_port_configuration_data(self,
784 entity_id,
785 bridge_id,
786 port_id,
787 tp_type,
788 tp_id):
789 frame = OmciFrame(
790 transaction_id=self.get_tx_id(),
791 message_type=OmciCreate.message_id,
792 omci_message=OmciCreate(
793 entity_class=MacBridgePortConfigurationData.class_id,
794 entity_id=entity_id,
795 data=dict(
796 bridge_id_pointer = bridge_id,
797 port_num=port_id,
798 tp_type=tp_type,
Steve Crooks9e85ce82017-03-20 12:00:53 -0400799 tp_pointer=tp_id
Steve Crooks3c2c7582017-01-10 15:02:26 -0600800 )
801 )
802 )
803 self.send_omci_message(frame)
804
Steve Crooks9e85ce82017-03-20 12:00:53 -0400805 def send_create_vlan_tagging_filter_data(self,
806 entity_id,
807 vlan_id):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600808 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400809 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600810 message_type=OmciCreate.message_id,
811 omci_message=OmciCreate(
812 entity_class=VlanTaggingFilterData.class_id,
813 entity_id=entity_id,
814 data=dict(
815 vlan_filter_0=vlan_id,
816 forward_operation=0x10,
817 number_of_entries=1
818 )
819 )
820 )
821 self.send_omci_message(frame)
822
rshettyf4bf19e2017-09-19 01:28:27 +0530823 def send_set_vlan_tagging_filter_data(self,
824 entity_id,
825 vlan_id):
826 data = dict(
827 vlan_filter_0=vlan_id,
828 forward_operation=0x10,
829 number_of_entries=1
830 )
831
832 frame = OmciFrame(
833 transaction_id=self.get_tx_id(),
834 message_type=OmciSet.message_id,
835 omci_message=OmciSet(
836 entity_class=VlanTaggingFilterData.class_id,
837 entity_id=entity_id,
838 attributes_mask=VlanTaggingFilterData.mask_for(
839 *data.keys()),
840 data=data
841 )
842 )
843 self.send_omci_message(frame)
844
845 def send_delete_vlan_tagging_filter_data(self,
846 entity_id):
847 frame = OmciFrame(
848 transaction_id=self.get_tx_id(),
849 message_type=OmciDelete.message_id,
850 omci_message=OmciDelete(
851 entity_class=VlanTaggingFilterData.class_id,
852 entity_id=entity_id
853 )
854 )
855 self.send_omci_message(frame)
856
Steve Crooks46d64302017-03-10 15:11:06 -0500857 def send_create_extended_vlan_tagging_operation_configuration_data(self,
858 entity_id,
859 assoc_type,
860 assoc_me):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600861 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400862 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600863 message_type=OmciCreate.message_id,
864 omci_message=OmciCreate(
865 entity_class=
866 ExtendedVlanTaggingOperationConfigurationData.class_id,
867 entity_id=entity_id,
868 data=dict(
Steve Crooks46d64302017-03-10 15:11:06 -0500869 association_type=assoc_type,
870 associated_me_pointer=assoc_me
Steve Crooks3c2c7582017-01-10 15:02:26 -0600871 )
872 )
873 )
874 self.send_omci_message(frame)
875
Steve Crooks9e85ce82017-03-20 12:00:53 -0400876 def send_set_extended_vlan_tagging_operation_tpid_configuration_data(self,
877 entity_id,
878 input_tpid,
879 output_tpid):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600880 data = dict(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400881 input_tpid=input_tpid,
882 output_tpid=output_tpid,
Steve Crooks3c2c7582017-01-10 15:02:26 -0600883 downstream_mode=0, # inverse of upstream
884 )
885 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400886 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600887 message_type=OmciSet.message_id,
888 omci_message=OmciSet(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400889 entity_class=
Steve Crooks3c2c7582017-01-10 15:02:26 -0600890 ExtendedVlanTaggingOperationConfigurationData.class_id,
891 entity_id=entity_id,
Steve Crooks9e85ce82017-03-20 12:00:53 -0400892 attributes_mask=
Steve Crooks3c2c7582017-01-10 15:02:26 -0600893 ExtendedVlanTaggingOperationConfigurationData.mask_for(
894 *data.keys()),
895 data=data
896 )
897 )
898 self.send_omci_message(frame)
899
Steve Crooksa9d0a7c2017-03-28 22:40:01 -0400900 def send_set_extended_vlan_tagging_operation_vlan_configuration_data_untagged(self,
901 entity_id,
902 filter_inner_vid,
903 treatment_inner_vid):
Steve Crooks3c2c7582017-01-10 15:02:26 -0600904 data = dict(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400905 received_frame_vlan_tagging_operation_table=
Steve Crooks3c2c7582017-01-10 15:02:26 -0600906 VlanTaggingOperation(
907 filter_outer_priority=15,
Steve Crooks46d64302017-03-10 15:11:06 -0500908 filter_outer_vid=4096,
909 filter_outer_tpid_de=0,
910
911 filter_inner_priority=15,
912 filter_inner_vid=filter_inner_vid,
913 filter_inner_tpid_de=0,
Steve Crooks3c2c7582017-01-10 15:02:26 -0600914 filter_ether_type=0,
Steve Crooks46d64302017-03-10 15:11:06 -0500915
916 treatment_tags_to_remove=0,
Steve Crooks3c2c7582017-01-10 15:02:26 -0600917 treatment_outer_priority=15,
Steve Crooks46d64302017-03-10 15:11:06 -0500918 treatment_outer_vid=0,
919 treatment_outer_tpid_de=0,
920
921 treatment_inner_priority=0,
922 treatment_inner_vid=treatment_inner_vid,
Steve Crooks3c2c7582017-01-10 15:02:26 -0600923 treatment_inner_tpid_de=4
924 )
925 )
926 frame = OmciFrame(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400927 transaction_id=self.get_tx_id(),
Steve Crooks3c2c7582017-01-10 15:02:26 -0600928 message_type=OmciSet.message_id,
929 omci_message=OmciSet(
Steve Crooks9e85ce82017-03-20 12:00:53 -0400930 entity_class=
Steve Crooks3c2c7582017-01-10 15:02:26 -0600931 ExtendedVlanTaggingOperationConfigurationData.class_id,
Steve Crooks9e85ce82017-03-20 12:00:53 -0400932 entity_id=entity_id,
933 attributes_mask=
Steve Crooks3c2c7582017-01-10 15:02:26 -0600934 ExtendedVlanTaggingOperationConfigurationData.mask_for(
935 *data.keys()),
936 data=data
937 )
938 )
939 self.send_omci_message(frame)
Zsolt Haraszticc153aa2016-12-14 02:28:59 -0800940
Steve Crooksa9d0a7c2017-03-28 22:40:01 -0400941 def send_set_extended_vlan_tagging_operation_vlan_configuration_data_single_tag(self,
942 entity_id,
943 filter_inner_priority,
944 filter_inner_vid,
945 filter_inner_tpid_de,
946 treatment_tags_to_remove,
947 treatment_inner_priority,
948 treatment_inner_vid):
949 data = dict(
950 received_frame_vlan_tagging_operation_table=
951 VlanTaggingOperation(
952 filter_outer_priority=15,
953 filter_outer_vid=4096,
954 filter_outer_tpid_de=0,
955
956 filter_inner_priority=filter_inner_priority,
957 filter_inner_vid=filter_inner_vid,
958 filter_inner_tpid_de=filter_inner_tpid_de,
959 filter_ether_type=0,
960
961 treatment_tags_to_remove=treatment_tags_to_remove,
962 treatment_outer_priority=15,
963 treatment_outer_vid=0,
964 treatment_outer_tpid_de=0,
965
966 treatment_inner_priority=treatment_inner_priority,
967 treatment_inner_vid=treatment_inner_vid,
968 treatment_inner_tpid_de=4
969 )
970 )
971 frame = OmciFrame(
972 transaction_id=self.get_tx_id(),
973 message_type=OmciSet.message_id,
974 omci_message=OmciSet(
975 entity_class=
976 ExtendedVlanTaggingOperationConfigurationData.class_id,
977 entity_id=entity_id,
978 attributes_mask=
979 ExtendedVlanTaggingOperationConfigurationData.mask_for(
980 *data.keys()),
981 data=data
982 )
983 )
984 self.send_omci_message(frame)
985
Steve Crooks9e85ce82017-03-20 12:00:53 -0400986 def send_create_multicast_operations_profile(self,
987 entity_id,
988 igmp_ver):
989 frame = OmciFrame(
990 transaction_id=self.get_tx_id(),
991 message_type=OmciCreate.message_id,
992 omci_message=OmciCreate(
993 entity_class=
994 MulticastOperationsProfile.class_id,
995 entity_id=entity_id,
996 data=dict(
997 igmp_version=igmp_ver,
998 igmp_function=0,
999 immediate_leave=0
1000 )
1001 )
1002 )
1003 self.send_omci_message(frame)
1004
1005 def send_set_multicast_operations_profile_acl_row0(self,
1006 entity_id,
1007 acl_table,
1008 row_key,
1009 gem_port,
1010 vlan,
1011 src_ip,
1012 dst_ip_start,
1013 dst_ip_end):
1014 row0 = AccessControlRow0(
1015 set_ctrl=1,
1016 row_part_id=0,
1017 test=0,
1018 row_key=row_key,
1019 gem_port_id=gem_port,
1020 vlan_id=vlan,
1021 src_ip=src_ip,
1022 dst_ip_start=dst_ip_start,
1023 dst_ip_end=dst_ip_end,
1024 ipm_group_bw=0
1025 )
1026
1027 if acl_table == 'dynamic':
1028 data = dict(
1029 dynamic_access_control_list_table=row0
1030 )
1031 else:
1032 data = dict(
1033 static_access_control_list_table=row0
1034 )
1035
1036 frame = OmciFrame(
1037 transaction_id=self.get_tx_id(),
1038 message_type=OmciSet.message_id,
1039 omci_message=OmciSet(
1040 entity_class=MulticastOperationsProfile.class_id,
1041 entity_id=entity_id,
1042 attributes_mask=MulticastOperationsProfile.mask_for(
1043 *data.keys()),
1044 data=data
1045 )
1046 )
1047 self.send_omci_message(frame)
1048
1049 def send_set_multicast_operations_profile_ds_igmp_mcast_tci(self,
1050 entity_id,
1051 ctrl_type,
1052 tci):
1053 data = dict(
1054 ds_igmp_mcast_tci=
1055 DownstreamIgmpMulticastTci(
1056 ctrl_type=ctrl_type,
1057 tci=tci
1058 )
1059 )
1060 frame = OmciFrame(
1061 transaction_id=self.get_tx_id(),
1062 message_type=OmciSet.message_id,
1063 omci_message=OmciSet(
1064 entity_class=MulticastOperationsProfile.class_id,
1065 entity_id=entity_id,
1066 attributes_mask=MulticastOperationsProfile.mask_for(
1067 *data.keys()),
1068 data=data
1069 )
1070 )
1071 self.send_omci_message(frame)
1072
1073 def send_create_multicast_subscriber_config_info(self,
1074 entity_id,
1075 me_type,
1076 mcast_oper_profile):
1077 frame = OmciFrame(
1078 transaction_id=self.get_tx_id(),
1079 message_type=OmciCreate.message_id,
1080 omci_message=OmciCreate(
1081 entity_class=
1082 MulticastSubscriberConfigInfo.class_id,
1083 entity_id=entity_id,
1084 data=dict(
1085 me_type=me_type,
1086 mcast_operations_profile_pointer=mcast_oper_profile
1087 )
1088 )
1089 )
1090 self.send_omci_message(frame)
1091
1092 def send_set_multicast_subscriber_config_info(self,
1093 entity_id,
1094 max_groups=0,
1095 max_mcast_bw=0,
1096 bw_enforcement=0):
1097 data = dict(
1098 max_simultaneous_groups=max_groups,
1099 max_multicast_bandwidth=max_mcast_bw,
1100 bandwidth_enforcement=bw_enforcement
1101 )
1102 frame = OmciFrame(
1103 transaction_id=self.get_tx_id(),
1104 message_type=OmciSet.message_id,
1105 omci_message=OmciSet(
1106 entity_class=MulticastSubscriberConfigInfo.class_id,
1107 entity_id=entity_id,
1108 attributes_mask=MulticastSubscriberConfigInfo.mask_for(
1109 *data.keys()),
1110 data=data
1111 )
1112 )
1113 self.send_omci_message(frame)
1114
1115 def send_set_multicast_service_package(self,
1116 entity_id,
1117 row_key,
1118 vid_uni,
1119 max_groups,
1120 max_mcast_bw,
1121 mcast_oper_profile):
1122 data = dict(
1123 multicast_service_package_table=
1124 MulticastServicePackage(
1125 set_ctrl=1,
1126 row_key=row_key,
1127
1128 vid_uni=vid_uni,
1129 max_simultaneous_groups=max_groups,
1130 max_multicast_bw=max_mcast_bw,
1131 mcast_operations_profile_pointer=mcast_oper_profile
1132 )
1133 )
1134 frame = OmciFrame(
1135 transaction_id=self.get_tx_id(),
1136 message_type=OmciSet.message_id,
1137 omci_message=OmciSet(
1138 entity_class=MulticastSubscriberConfigInfo.class_id,
1139 entity_id=entity_id,
1140 attributes_mask=MulticastSubscriberConfigInfo.mask_for(
1141 *data.keys()),
1142 data=data
1143 )
1144 )
1145 self.send_omci_message(frame)
1146
1147 def send_set_multicast_allowed_preview_groups_row0(self,
1148 entity_id,
1149 row_key,
1150 src_ip,
1151 vlan_id_ani,
1152 vlan_id_uni):
1153 data = dict(
1154 allowed_preview_groups_table=
1155 AllowedPreviewGroupsRow0(
1156 set_ctrl=1,
1157 row_part_id=0,
1158 row_key=row_key,
1159
1160 src_ip=src_ip,
1161 vlan_id_ani=vlan_id_ani,
1162 vlan_id_uni=vlan_id_uni
1163 )
1164 )
1165 frame = OmciFrame(
1166 transaction_id=self.get_tx_id(),
1167 message_type=OmciSet.message_id,
1168 omci_message=OmciSet(
1169 entity_class=MulticastSubscriberConfigInfo.class_id,
1170 entity_id=entity_id,
1171 attributes_mask=MulticastSubscriberConfigInfo.mask_for(
1172 *data.keys()),
1173 data=data
1174 )
1175 )
1176 self.send_omci_message(frame)
1177
1178 def send_set_multicast_allowed_preview_groups_row1(self,
1179 entity_id,
1180 row_key,
1181 dst_ip,
1182 duration,
1183 time_left):
1184 data = dict(
1185 allowed_preview_groups_table=
1186 AllowedPreviewGroupsRow1(
1187 set_ctrl=1,
1188 row_part_id=1,
1189 row_key=row_key,
1190
1191 dst_ip=dst_ip,
1192 duration=duration,
1193 time_left=time_left
1194 )
1195 )
1196 frame = OmciFrame(
1197 transaction_id=self.get_tx_id(),
1198 message_type=OmciSet.message_id,
1199 omci_message=OmciSet(
1200 entity_class=MulticastSubscriberConfigInfo.class_id,
1201 entity_id=entity_id,
1202 attributes_mask=MulticastSubscriberConfigInfo.mask_for(
1203 *data.keys()),
1204 data=data
1205 )
1206 )
1207 self.send_omci_message(frame)
1208
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001209 @inlineCallbacks
Steve Crooks3c2c7582017-01-10 15:02:26 -06001210 def wait_for_response(self):
1211 log.info('wait-for-response')
1212 try:
1213 response = yield self.incoming_messages.get()
Steve Crooks9e85ce82017-03-20 12:00:53 -04001214 log.info('got-response')
1215 # resp = OmciFrame(response)
1216 # resp.show()
Steve Crooks3c2c7582017-01-10 15:02:26 -06001217 except Exception as e:
1218 self.log.info('wait-for-response-exception', exc=str(e))
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001219
Steve Crooks3c2c7582017-01-10 15:02:26 -06001220 @inlineCallbacks
Steve Crooks9b160d72017-03-31 10:48:29 -05001221 def message_exchange(self, onu, gem, cvid):
1222 log.info('message_exchange', onu=onu, gem=gem, cvid=cvid)
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001223 # reset incoming message queue
1224 while self.incoming_messages.pending:
1225 _ = yield self.incoming_messages.get()
1226
rshettyf4bf19e2017-09-19 01:28:27 +05301227 cvid = BRDCM_DEFAULT_VLAN
Steve Crooks9b160d72017-03-31 10:48:29 -05001228
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001229 # construct message
Steve Crooks3c2c7582017-01-10 15:02:26 -06001230 # MIB Reset - OntData - 0
1231 self.send_mib_reset()
1232 yield self.wait_for_response()
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001233
Steve Crooks3c2c7582017-01-10 15:02:26 -06001234 # Create AR - GalEthernetProfile - 1
1235 self.send_create_gal_ethernet_profile(1, 48)
1236 yield self.wait_for_response()
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001237
rshettyf4bf19e2017-09-19 01:28:27 +05301238 # Port 2
1239 # Extended VLAN Tagging Operation config
1240 # Create AR - ExtendedVlanTaggingOperationConfigData - 514 - 2 - 0x102(Uni-Port-Num)
1241 # TODO: add entry here for additional UNI interfaces
1242 self.send_create_extended_vlan_tagging_operation_configuration_data(0x202, 2, 0x102)
Steve Crooks3c2c7582017-01-10 15:02:26 -06001243 yield self.wait_for_response()
Zsolt Haraszticc153aa2016-12-14 02:28:59 -08001244
rshettyf4bf19e2017-09-19 01:28:27 +05301245 # Set AR - ExtendedVlanTaggingOperationConfigData - 514 - 8100 - 8100
1246 self.send_set_extended_vlan_tagging_operation_tpid_configuration_data(0x202, 0x8100, 0x8100)
Steve Crooks3c2c7582017-01-10 15:02:26 -06001247 yield self.wait_for_response()
1248
Steve Crooks9b160d72017-03-31 10:48:29 -05001249 # MAC Bridge Service config
Steve Crooks3c2c7582017-01-10 15:02:26 -06001250 # Create AR - MacBridgeServiceProfile - 513
1251 self.send_create_mac_bridge_service_profile(0x201)
1252 yield self.wait_for_response()
1253
rshettyf4bf19e2017-09-19 01:28:27 +05301254 # Create AR - MacBridgePortConfigData - Entity_id -
1255 # bridge ID -
1256 # port num -
1257 # tp_type -
1258 # IEEE MApper poniter
1259 self.send_create_mac_bridge_port_configuration_data(0x201, 0x201, 2, 1, 0x102)
Steve Crooks9e85ce82017-03-20 12:00:53 -04001260 yield self.wait_for_response()
1261
rshettyf4bf19e2017-09-19 01:28:27 +05301262 # Mapper Service config
1263 # Create AR - 802.1pMapperServiceProfile - 32769
1264 self.send_create_8021p_mapper_service_profile(0x8001)
Steve Crooks3c2c7582017-01-10 15:02:26 -06001265 yield self.wait_for_response()
1266
Steve Crooks9b160d72017-03-31 10:48:29 -05001267 # MAC Bridge Port config
Steve Crooks3c2c7582017-01-10 15:02:26 -06001268 # Create AR - MacBridgePortConfigData - 8450 - 513 - 3 - 3 - 32769
1269 self.send_create_mac_bridge_port_configuration_data(0x2102, 0x201, 3, 3, 0x8001)
1270 yield self.wait_for_response()
1271
Steve Crooks9b160d72017-03-31 10:48:29 -05001272 # VLAN Tagging Filter config
1273 # Create AR - VlanTaggingFilterData - 8450 - c-vid
1274 self.send_create_vlan_tagging_filter_data(0x2102, cvid)
Steve Crooks3c2c7582017-01-10 15:02:26 -06001275 yield self.wait_for_response()
1276
rshettyf4bf19e2017-09-19 01:28:27 +05301277 # Set AR - ExtendedVlanTaggingOperationConfigData
1278 # 514 - RxVlanTaggingOperationTable - add VLAN <cvid> to priority tagged pkts - c-vid
1279 #self.send_set_extended_vlan_tagging_operation_vlan_configuration_data_single_tag(0x202, 8, 0, 0, 1, 8, cvid)
1280 #yield self.wait_for_response()
1281
1282 # Set AR - ExtendedVlanTaggingOperationConfigData
1283 # 514 - RxVlanTaggingOperationTable - add VLAN <cvid> to untagged pkts - c-vid
1284 self.send_set_extended_vlan_tagging_operation_vlan_configuration_data_untagged(0x202, 0x1000, cvid)
1285 yield self.wait_for_response()
1286
1287 # Multicast related MEs
1288 # Set AR - MulticastOperationsProfile - Dynamic Access Control List table
1289 # Create AR - MacBridgePortConfigData - 9000 - 513 - 6 - 6 - 6
1290 self.send_create_mac_bridge_port_configuration_data(0x2328, 0x201, 6, 6, 6)
1291 yield self.wait_for_response()
1292
Steve Crooks9b160d72017-03-31 10:48:29 -05001293 # Multicast Operation Profile config
Steve Crooks9e85ce82017-03-20 12:00:53 -04001294 # Create AR - MulticastOperationsProfile
1295 self.send_create_multicast_operations_profile(0x201, 3)
1296 yield self.wait_for_response()
1297
rshettyf4bf19e2017-09-19 01:28:27 +05301298 # Multicast Subscriber config
1299 # Create AR - MulticastSubscriberConfigInfo
1300 self.send_create_multicast_subscriber_config_info(0x201, 0, 0x201)
1301 yield self.wait_for_response()
1302
1303 # Create AR - GemPortNetworkCtp - 260 - 4000 - 0 Multicast
1304 self.send_create_gem_port_network_ctp(0x104, 0x0FA0, 0, "downstream", 0)
1305 yield self.wait_for_response()
1306
1307 # Multicast GEM Interworking config Multicast
1308 # Create AR - MulticastGemInterworkingTp - 6 - 260
1309 self.send_create_multicast_gem_interworking_tp(0x6, 0x104)
1310 yield self.wait_for_response()
1311
Steve Crooks9e85ce82017-03-20 12:00:53 -04001312 self.send_set_multicast_operations_profile_acl_row0(0x201,
1313 'dynamic',
1314 0,
1315 0x0fa0,
1316 0x0fa0,
1317 '0.0.0.0',
1318 '224.0.0.0',
1319 '239.255.255.255')
1320 yield self.wait_for_response()
1321
Steve Crooks9b160d72017-03-31 10:48:29 -05001322 # Multicast Operation Profile config
Steve Crooks9e85ce82017-03-20 12:00:53 -04001323 # Set AR - MulticastOperationsProfile - Downstream IGMP Multicast TCI
Steve Crooks9b160d72017-03-31 10:48:29 -05001324 self.send_set_multicast_operations_profile_ds_igmp_mcast_tci(0x201, 4, cvid)
Steve Crooks9e85ce82017-03-20 12:00:53 -04001325 yield self.wait_for_response()
1326
rshettyf4bf19e2017-09-19 01:28:27 +05301327 '''
Steve Crooks9b160d72017-03-31 10:48:29 -05001328 # Port 5
1329 # Extended VLAN Tagging Operation config
1330 # Create AR - ExtendedVlanTaggingOperationConfigData - 514 - 2 - 0x102
1331 # TODO: add entry here for additional UNI interfaces
1332 self.send_create_extended_vlan_tagging_operation_configuration_data(0x205, 2, 0x105)
1333 yield self.wait_for_response()
1334
1335 # Set AR - ExtendedVlanTaggingOperationConfigData - 514 - 8100 - 8100
1336 self.send_set_extended_vlan_tagging_operation_tpid_configuration_data(0x205, 0x8100, 0x8100)
1337 yield self.wait_for_response()
1338
1339 # Set AR - ExtendedVlanTaggingOperationConfigData
1340 # 514 - RxVlanTaggingOperationTable - add VLAN <cvid> to priority tagged pkts - c-vid
1341 #self.send_set_extended_vlan_tagging_operation_vlan_configuration_data_single_tag(0x205, 8, 0, 0, 1, 8, cvid)
1342 #yield self.wait_for_response()
1343
1344 # Set AR - ExtendedVlanTaggingOperationConfigData
1345 # 514 - RxVlanTaggingOperationTable - add VLAN <cvid> to untagged pkts - c-vid
1346 self.send_set_extended_vlan_tagging_operation_vlan_configuration_data_untagged(0x205, 0x1000, cvid)
1347 yield self.wait_for_response()
1348
1349 # MAC Bridge Port config
1350 # Create AR - MacBridgePortConfigData - 513 - 513 - 1 - 1 - 0x102
1351 # TODO: add more entries here for other UNI ports
1352 self.send_create_mac_bridge_port_configuration_data(0x205, 0x201, 5, 1, 0x105)
Steve Crooks3c2c7582017-01-10 15:02:26 -06001353 yield self.wait_for_response()
rshettyf4bf19e2017-09-19 01:28:27 +05301354 '''
1355
1356 def add_uni_port(self, device, parent_logical_device_id,
1357 name, parent_port_num=None):
1358 self.log.info('adding-logical-port', device_id=device.id,
1359 logical_device_id=parent_logical_device_id,
1360 name=name)
1361 if parent_port_num is not None:
1362 uni = parent_port_num
1363 port_no = parent_port_num
1364 else:
1365 uni = self.uni_ports[0]
1366 port_no = device.proxy_address.channel_id + uni
1367 # register physical ports
1368 uni_port = Port(
1369 port_no=uni,
1370 label='UNI facing Ethernet port '+str(uni),
1371 type=Port.ETHERNET_UNI,
1372 admin_state=AdminState.ENABLED,
1373 oper_status=OperStatus.ACTIVE
1374 )
1375 self.adapter_agent.add_port(device.id, uni_port)
1376 # add uni port to logical device
1377 cap = OFPPF_1GB_FD | OFPPF_FIBER
1378 self.adapter_agent.add_logical_port(parent_logical_device_id,
1379 LogicalPort(
1380 id='uni-{}'.format(port_no),
1381 ofp_port=ofp_port(
1382 port_no=port_no,
1383 hw_addr=mac_str_to_tuple('00:00:00:%02x:%02x:%02x' %
1384 (device.proxy_address.onu_id & 0xff,
1385 (port_no >> 8) & 0xff,
1386 port_no & 0xff)),
1387 #name='uni-{}'.format(port_no),
1388 name=name,
1389 config=0,
1390 state=OFPPS_LIVE,
1391 curr=cap,
1392 advertised=cap,
1393 peer=cap,
1394 curr_speed=OFPPF_1GB_FD,
1395 max_speed=OFPPF_1GB_FD
1396 ),
1397 device_id=device.id,
1398 device_port_no=uni_port.port_no
1399 ))
rshettyc26a3c32017-07-27 11:06:38 +05301400
1401 def create_interface(self, data):
rshetty1cc73982017-09-02 03:31:12 +05301402 if isinstance(data, VEnetConfig):
1403 parent_port_num = None
1404 onu_device = self.adapter_agent.get_device(self.device_id)
1405 ports = self.adapter_agent.get_ports(onu_device.parent_id, Port.ETHERNET_UNI)
1406 parent_port_num = None
1407 for port in ports:
1408 if port.label == data.interface.name:
1409 parent_port_num = port.port_no
1410 break
1411
rshettyf4bf19e2017-09-19 01:28:27 +05301412 parent_device = self.adapter_agent.get_device(onu_device.parent_id)
1413 logical_device_id = parent_device.parent_id
1414 assert logical_device_id
1415 self.add_uni_port(onu_device, logical_device_id,
1416 data.name, parent_port_num)
1417
1418 if parent_port_num is None:
rshetty1cc73982017-09-02 03:31:12 +05301419 self.log.error("matching-parent-uni-port-num-not-found")
1420 return
1421
1422 onu_ports = self.adapter_agent.get_ports(self.device_id, Port.PON_ONU)
1423 if onu_ports:
1424 # To-Do :
1425 # Assumed only one PON port and UNI port per ONU.
1426 pon_port = onu_ports[0]
1427 else:
1428 self.log.error("No-Pon-port-configured-yet")
1429 return
1430
1431 self.adapter_agent.delete_port_reference_from_parent(self.device_id,
1432 pon_port)
1433
1434 pon_port.peers[0].device_id = onu_device.parent_id
1435 pon_port.peers[0].port_no = parent_port_num
1436 self.adapter_agent.add_port_reference_to_parent(self.device_id,
1437 pon_port)
1438 else:
1439 self.log.info('Not handled Yet')
1440 return
rshettyc26a3c32017-07-27 11:06:38 +05301441
1442 def update_interface(self, data):
1443 self.log.info('Not Implemented yet')
rshetty1cc73982017-09-02 03:31:12 +05301444 return
rshettyc26a3c32017-07-27 11:06:38 +05301445
1446 def remove_interface(self, data):
1447 self.log.info('Not Implemented yet')
rshetty1cc73982017-09-02 03:31:12 +05301448 return
rshettyf4bf19e2017-09-19 01:28:27 +05301449
1450 @inlineCallbacks
1451 def create_gemport(self, data):
1452 log.info('create-gemport')
1453 gem_port= GemportsConfigData()
1454 gem_port.CopyFrom(data)
1455 if gem_port.tcont_ref is None:
1456 self.log.info('Recevied NULL Gem Port Data')
1457 else:
1458 #To-Do Need to see how the valuse 0x8001 is derived
1459 self.send_create_gem_port_network_ctp(gem_port.gemport_id,
1460 gem_port.gemport_id, 0x8001,
1461 "bi-directional", 0x100)
1462 yield self.wait_for_response()
1463
1464 # GEM Interworking config
1465 # Create AR - GemInterworkingTp - Gem_port,TP_pointer -
1466 # Gem port CTP pointer -
1467 # Mapper service profile id
1468 self.send_create_gem_inteworking_tp(gem_port.gemport_id,
1469 gem_port.gemport_id, 0x8001)
1470 yield self.wait_for_response()
1471
1472 # Mapper Service Profile config
1473 # Set AR - 802.1pMapperServiceProfile - Mapper_ profile_id -
1474 # gem_port_tp pointer
1475 self.send_set_8021p_mapper_service_profile(0x8001,
1476 gem_port.gemport_id)
1477 yield self.wait_for_response()
1478
1479
1480 @inlineCallbacks
1481 def create_tcont(self, tcont_data, traffic_descriptor_data):
1482 log.info('create-tcont')
1483 tcont = TcontsConfigData()
1484 tcont.CopyFrom(tcont_data)
1485 if (tcont.interface_reference is not None):
1486 self.log.info('tcont created is', tcont= tcont.alloc_id)
1487 self.send_set_tcont(0x8001, tcont.alloc_id)
1488 yield self.wait_for_response()
1489 else:
1490 self.log.info('Recevied NULL tcont Data', tcont= tcont.alloc_id)
1491
1492 def create_multicast_gemport(self, data):
1493 self.log.info('Send relevant OMCI message')