Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -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 | 656ecc6 | 2016-12-28 15:08:23 -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 | Fully simulated OLT/ONU adapter. |
| 19 | """ |
| 20 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 21 | import sys |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 22 | import structlog |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 23 | from twisted.internet.defer import DeferredQueue, inlineCallbacks |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 24 | from common.utils.asleep import asleep |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 25 | |
Shad Ansari | d1aa9e7 | 2017-06-23 21:34:25 -0700 | [diff] [blame] | 26 | from voltha.adapters.iadapter import OnuAdapter |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 27 | from voltha.core.logical_device_agent import mac_str_to_tuple |
| 28 | from voltha.protos import third_party |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 29 | from voltha.protos.common_pb2 import OperStatus, ConnectStatus, AdminState |
| 30 | from voltha.protos.device_pb2 import Port |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 31 | from voltha.protos.logical_device_pb2 import LogicalPort |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 32 | from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \ |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 33 | OFPPF_1GB_FD |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 34 | from voltha.protos.openflow_13_pb2 import ofp_port |
| 35 | from voltha.protos.ponsim_pb2 import FlowTable |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 36 | from voltha.protos.ponsim_pb2 import InterfaceConfig |
| 37 | from voltha.protos.bbf_fiber_base_pb2 import OntaniConfig, VOntaniConfig, \ |
| 38 | VEnetConfig |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 39 | from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import \ |
| 40 | TrafficDescriptorProfileData |
| 41 | from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData |
| 42 | from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData |
| 43 | from voltha.protos.bbf_fiber_multicast_gemport_body_pb2 import \ |
| 44 | MulticastGemportsConfigData |
| 45 | from voltha.protos.bbf_fiber_multicast_distribution_set_body_pb2 import \ |
| 46 | MulticastDistributionSetData |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 47 | |
| 48 | _ = third_party |
| 49 | log = structlog.get_logger() |
| 50 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 51 | xpon_ponsim_onu_itfs = { |
| 52 | 'create_interface': { |
| 53 | 'log': 'create-interface'}, |
| 54 | 'update_interface': { |
| 55 | 'log': 'update-interface'}, |
| 56 | 'remove_interface': { |
| 57 | 'log': 'remove-interface'}, |
| 58 | 'create_tcont': { |
| 59 | 'log': 'create-tconts-config-data'}, |
| 60 | 'update_tcont': { |
| 61 | 'log': 'update-tconts-config-data'}, |
| 62 | 'remove_tcont': { |
| 63 | 'log': 'remove-tconts-config-data'}, |
| 64 | 'create_gemport': { |
| 65 | 'log': 'create-gemports-config-data'}, |
| 66 | 'update_gemport': { |
| 67 | 'log': 'update-gemports-config-data'}, |
| 68 | 'remove_gemport': { |
| 69 | 'log': 'remove-gemports-config-data'}, |
| 70 | 'create_multicast_gemport': { |
| 71 | 'log': 'create-multicast-gemports-config-data'}, |
| 72 | 'update_multicast_gemport': { |
| 73 | 'log': 'update-multicast-gemports-config-data'}, |
| 74 | 'remove_multicast_gemport': { |
| 75 | 'log': 'remove-multicast-gemports-config-data'}, |
| 76 | 'create_multicast_distribution_set': { |
| 77 | 'log': 'create-multicast-distribution-set-data'}, |
| 78 | 'update_multicast_distribution_set': { |
| 79 | 'log': 'update-multicast-distribution-set-data'}, |
| 80 | 'remove_multicast_distribution_set': { |
| 81 | 'log': 'remove-multicast-distribution-set-data'}, |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 84 | |
Shad Ansari | d1aa9e7 | 2017-06-23 21:34:25 -0700 | [diff] [blame] | 85 | class PonSimOnuAdapter(OnuAdapter): |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 86 | def __init__(self, adapter_agent, config): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 87 | # DeviceType of ONU should be same as VENDOR ID of ONU Serial Number as specified by standard |
| 88 | # requires for identifying correct adapter or ranged ONU |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 89 | super(PonSimOnuAdapter, self).__init__(adapter_agent=adapter_agent, |
| 90 | config=config, |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 91 | device_handler_class=PonSimOnuHandler, |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 92 | name='ponsim_onu', |
| 93 | vendor='Voltha project', |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 94 | version='0.4', |
Niren R Chidrawar | efcebcd | 2017-07-19 20:03:39 -0400 | [diff] [blame] | 95 | device_type='ponsim_onu', |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 96 | vendor_id='PSMO', |
| 97 | accepts_bulk_flow_update=True, |
| 98 | accepts_add_remove_flow_updates=False) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 99 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 100 | def xpon_ponsim_onu_adapter_interface(self, method_name, device, data, |
| 101 | data2=None): |
| 102 | log.info('{}'.format(xpon_ponsim_onu_itfs[method_name]['log']), |
| 103 | device_id=device.id) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 104 | if device.id in self.devices_handlers: |
| 105 | handler = self.devices_handlers[device.id] |
| 106 | if handler is not None: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 107 | _method = getattr(handler, method_name) |
| 108 | if isinstance(data, TcontsConfigData): |
| 109 | _method(data, data2) |
| 110 | else: |
| 111 | _method(data) |
| 112 | |
| 113 | def create_interface(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 114 | _method_name = sys._getframe().f_code.co_name |
| 115 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 116 | |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 117 | def update_interface(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 118 | _method_name = sys._getframe().f_code.co_name |
| 119 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 120 | |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 121 | def remove_interface(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 122 | _method_name = sys._getframe().f_code.co_name |
| 123 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 124 | |
| 125 | def create_tcont(self, device, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 126 | _method_name = sys._getframe().f_code.co_name |
| 127 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, |
| 128 | tcont_data, |
| 129 | traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 130 | |
| 131 | def update_tcont(self, device, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 132 | _method_name = sys._getframe().f_code.co_name |
| 133 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, |
| 134 | tcont_data, |
| 135 | traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 136 | |
| 137 | def remove_tcont(self, device, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 138 | _method_name = sys._getframe().f_code.co_name |
| 139 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, |
| 140 | tcont_data, |
| 141 | traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 142 | |
| 143 | def create_gemport(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 144 | _method_name = sys._getframe().f_code.co_name |
| 145 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 146 | |
| 147 | def update_gemport(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 148 | _method_name = sys._getframe().f_code.co_name |
| 149 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 150 | |
| 151 | def remove_gemport(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 152 | _method_name = sys._getframe().f_code.co_name |
| 153 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 154 | |
| 155 | def create_multicast_gemport(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 156 | _method_name = sys._getframe().f_code.co_name |
| 157 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 158 | |
| 159 | def update_multicast_gemport(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 160 | _method_name = sys._getframe().f_code.co_name |
| 161 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 162 | |
| 163 | def remove_multicast_gemport(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 164 | _method_name = sys._getframe().f_code.co_name |
| 165 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 166 | |
| 167 | def create_multicast_distribution_set(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 168 | _method_name = sys._getframe().f_code.co_name |
| 169 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 170 | |
| 171 | def update_multicast_distribution_set(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 172 | _method_name = sys._getframe().f_code.co_name |
| 173 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 174 | |
| 175 | def remove_multicast_distribution_set(self, device, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 176 | _method_name = sys._getframe().f_code.co_name |
| 177 | self.xpon_ponsim_onu_adapter_interface(_method_name, device, data) |
| 178 | |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 179 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 180 | class PonSimOnuHandler(object): |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 181 | def __init__(self, adapter, device_id): |
| 182 | self.adapter = adapter |
| 183 | self.adapter_agent = adapter.adapter_agent |
| 184 | self.device_id = device_id |
| 185 | self.log = structlog.get_logger(device_id=device_id) |
| 186 | self.incoming_messages = DeferredQueue() |
| 187 | self.proxy_address = None |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 188 | # reference of uni_port is required when re-enabling the device if |
| 189 | # it was disabled previously |
| 190 | self.uni_port = None |
| 191 | self.pon_port = None |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 192 | |
| 193 | def receive_message(self, msg): |
| 194 | self.incoming_messages.put(msg) |
| 195 | |
| 196 | def activate(self, device): |
| 197 | self.log.info('activating') |
| 198 | |
| 199 | # first we verify that we got parent reference and proxy info |
| 200 | assert device.parent_id |
| 201 | assert device.proxy_address.device_id |
| 202 | assert device.proxy_address.channel_id |
| 203 | |
| 204 | # register for proxied messages right away |
| 205 | self.proxy_address = device.proxy_address |
| 206 | self.adapter_agent.register_for_proxied_messages(device.proxy_address) |
| 207 | |
| 208 | # populate device info |
Andy Bavier | ea82b46 | 2018-07-27 16:48:13 -0700 | [diff] [blame^] | 209 | device.root = False |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 210 | device.vendor = 'ponsim' |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 211 | device.model = 'n/a' |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 212 | device.connect_status = ConnectStatus.REACHABLE |
| 213 | self.adapter_agent.update_device(device) |
| 214 | |
| 215 | # register physical ports |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 216 | self.uni_port = Port( |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 217 | port_no=2, |
| 218 | label='UNI facing Ethernet port', |
| 219 | type=Port.ETHERNET_UNI, |
| 220 | admin_state=AdminState.ENABLED, |
| 221 | oper_status=OperStatus.ACTIVE |
| 222 | ) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 223 | self.pon_port = Port( |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 224 | port_no=1, |
| 225 | label='PON port', |
| 226 | type=Port.PON_ONU, |
| 227 | admin_state=AdminState.ENABLED, |
| 228 | oper_status=OperStatus.ACTIVE, |
| 229 | peers=[ |
| 230 | Port.PeerPort( |
| 231 | device_id=device.parent_id, |
| 232 | port_no=device.parent_port_no |
| 233 | ) |
| 234 | ] |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 235 | ) |
| 236 | self.adapter_agent.add_port(device.id, self.uni_port) |
| 237 | self.adapter_agent.add_port(device.id, self.pon_port) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 238 | |
| 239 | # add uni port to logical device |
| 240 | parent_device = self.adapter_agent.get_device(device.parent_id) |
| 241 | logical_device_id = parent_device.parent_id |
| 242 | assert logical_device_id |
| 243 | port_no = device.proxy_address.channel_id |
| 244 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
| 245 | self.adapter_agent.add_logical_port(logical_device_id, LogicalPort( |
| 246 | id='uni-{}'.format(port_no), |
| 247 | ofp_port=ofp_port( |
| 248 | port_no=port_no, |
| 249 | hw_addr=mac_str_to_tuple('00:00:00:00:00:%02x' % port_no), |
Andy Bavier | ea82b46 | 2018-07-27 16:48:13 -0700 | [diff] [blame^] | 250 | name=device.serial_number, |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 251 | config=0, |
| 252 | state=OFPPS_LIVE, |
| 253 | curr=cap, |
| 254 | advertised=cap, |
| 255 | peer=cap, |
| 256 | curr_speed=OFPPF_1GB_FD, |
| 257 | max_speed=OFPPF_1GB_FD |
| 258 | ), |
| 259 | device_id=device.id, |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 260 | device_port_no=self.uni_port.port_no |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 261 | )) |
| 262 | |
| 263 | device = self.adapter_agent.get_device(device.id) |
| 264 | device.oper_status = OperStatus.ACTIVE |
| 265 | self.adapter_agent.update_device(device) |
| 266 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 267 | def _get_uni_port(self): |
| 268 | ports = self.adapter_agent.get_ports(self.device_id, Port.ETHERNET_UNI) |
| 269 | if ports: |
| 270 | # For now, we use on one uni port |
| 271 | return ports[0] |
| 272 | |
| 273 | def _get_pon_port(self): |
| 274 | ports = self.adapter_agent.get_ports(self.device_id, Port.PON_ONU) |
| 275 | if ports: |
| 276 | # For now, we use on one uni port |
| 277 | return ports[0] |
| 278 | |
| 279 | def reconcile(self, device): |
| 280 | self.log.info('reconciling-ONU-device-starts') |
| 281 | |
| 282 | # first we verify that we got parent reference and proxy info |
| 283 | assert device.parent_id |
| 284 | assert device.proxy_address.device_id |
| 285 | assert device.proxy_address.channel_id |
| 286 | |
| 287 | # register for proxied messages right away |
| 288 | self.proxy_address = device.proxy_address |
| 289 | self.adapter_agent.register_for_proxied_messages(device.proxy_address) |
| 290 | |
| 291 | # Set the connection status to REACHABLE |
| 292 | device.connect_status = ConnectStatus.REACHABLE |
| 293 | self.adapter_agent.update_device(device) |
| 294 | |
| 295 | # TODO: Verify that the uni, pon and logical ports exists |
| 296 | |
| 297 | # Mark the device as REACHABLE and ACTIVE |
| 298 | device = self.adapter_agent.get_device(device.id) |
| 299 | device.connect_status = ConnectStatus.REACHABLE |
| 300 | device.oper_status = OperStatus.ACTIVE |
| 301 | self.adapter_agent.update_device(device) |
| 302 | |
| 303 | self.log.info('reconciling-ONU-device-ends') |
| 304 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 305 | @inlineCallbacks |
| 306 | def update_flow_table(self, flows): |
| 307 | |
| 308 | # we need to proxy through the OLT to get to the ONU |
| 309 | |
| 310 | # reset response queue |
| 311 | while self.incoming_messages.pending: |
| 312 | yield self.incoming_messages.get() |
| 313 | |
| 314 | msg = FlowTable( |
| 315 | port=self.proxy_address.channel_id, |
| 316 | flows=flows |
| 317 | ) |
| 318 | self.adapter_agent.send_proxied_message(self.proxy_address, msg) |
| 319 | |
| 320 | yield self.incoming_messages.get() |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 321 | |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 322 | def remove_from_flow_table(self, flows): |
| 323 | self.log.debug('remove-from-flow-table', flows=flows) |
| 324 | # TODO: Update PONSIM code to accept incremental flow changes. |
| 325 | # Once completed, the accepts_add_remove_flow_updates for this |
| 326 | # device type can be set to True |
| 327 | |
| 328 | def add_to_flow_table(self, flows): |
| 329 | self.log.debug('add-to-flow-table', flows=flows) |
| 330 | # TODO: Update PONSIM code to accept incremental flow changes |
| 331 | # Once completed, the accepts_add_remove_flow_updates for this |
| 332 | # device type can be set to True |
| 333 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 334 | @inlineCallbacks |
| 335 | def reboot(self): |
| 336 | self.log.info('rebooting', device_id=self.device_id) |
| 337 | |
| 338 | # Update the operational status to ACTIVATING and connect status to |
| 339 | # UNREACHABLE |
| 340 | device = self.adapter_agent.get_device(self.device_id) |
| 341 | previous_oper_status = device.oper_status |
| 342 | previous_conn_status = device.connect_status |
| 343 | device.oper_status = OperStatus.ACTIVATING |
| 344 | device.connect_status = ConnectStatus.UNREACHABLE |
| 345 | self.adapter_agent.update_device(device) |
| 346 | |
| 347 | # Sleep 10 secs, simulating a reboot |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 348 | # TODO: send alert and clear alert after the reboot |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 349 | yield asleep(10) |
| 350 | |
| 351 | # Change the operational status back to its previous state. With a |
| 352 | # real OLT the operational state should be the state the device is |
| 353 | # after a reboot. |
| 354 | # Get the latest device reference |
| 355 | device = self.adapter_agent.get_device(self.device_id) |
| 356 | device.oper_status = previous_oper_status |
| 357 | device.connect_status = previous_conn_status |
| 358 | self.adapter_agent.update_device(device) |
| 359 | self.log.info('rebooted', device_id=self.device_id) |
| 360 | |
sathishg | 5ae8622 | 2017-06-28 15:16:29 +0530 | [diff] [blame] | 361 | def self_test_device(self, device): |
| 362 | """ |
| 363 | This is called to Self a device based on a NBI call. |
| 364 | :param device: A Voltha.Device object. |
| 365 | :return: Will return result of self test |
| 366 | """ |
| 367 | log.info('self-test-device', device=device.id) |
| 368 | raise NotImplementedError() |
| 369 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 370 | def disable(self): |
| 371 | self.log.info('disabling', device_id=self.device_id) |
| 372 | |
| 373 | # Get the latest device reference |
| 374 | device = self.adapter_agent.get_device(self.device_id) |
| 375 | |
| 376 | # Disable all ports on that device |
| 377 | self.adapter_agent.disable_all_ports(self.device_id) |
| 378 | |
| 379 | # Update the device operational status to UNKNOWN |
| 380 | device.oper_status = OperStatus.UNKNOWN |
| 381 | device.connect_status = ConnectStatus.UNREACHABLE |
| 382 | self.adapter_agent.update_device(device) |
| 383 | |
| 384 | # Remove the uni logical port from the OLT, if still present |
| 385 | parent_device = self.adapter_agent.get_device(device.parent_id) |
| 386 | assert parent_device |
| 387 | logical_device_id = parent_device.parent_id |
| 388 | assert logical_device_id |
| 389 | port_no = device.proxy_address.channel_id |
| 390 | port_id = 'uni-{}'.format(port_no) |
| 391 | try: |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 392 | port = self.adapter_agent.get_logical_port(logical_device_id, |
| 393 | port_id) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 394 | self.adapter_agent.delete_logical_port(logical_device_id, port) |
| 395 | except KeyError: |
| 396 | self.log.info('logical-port-not-found', device_id=self.device_id, |
| 397 | portid=port_id) |
| 398 | |
| 399 | # Remove pon port from parent |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 400 | self.pon_port = self._get_pon_port() |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 401 | self.adapter_agent.delete_port_reference_from_parent(self.device_id, |
| 402 | self.pon_port) |
| 403 | |
| 404 | # Just updating the port status may be an option as well |
| 405 | # port.ofp_port.config = OFPPC_NO_RECV |
| 406 | # yield self.adapter_agent.update_logical_port(logical_device_id, |
| 407 | # port) |
| 408 | # Unregister for proxied message |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 409 | self.adapter_agent.unregister_for_proxied_messages( |
| 410 | device.proxy_address) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 411 | |
| 412 | # TODO: |
| 413 | # 1) Remove all flows from the device |
| 414 | # 2) Remove the device from ponsim |
| 415 | |
| 416 | self.log.info('disabled', device_id=device.id) |
| 417 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 418 | def reenable(self): |
| 419 | self.log.info('re-enabling', device_id=self.device_id) |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 420 | try: |
| 421 | # Get the latest device reference |
| 422 | device = self.adapter_agent.get_device(self.device_id) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 423 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 424 | # First we verify that we got parent reference and proxy info |
| 425 | assert device.parent_id |
| 426 | assert device.proxy_address.device_id |
| 427 | assert device.proxy_address.channel_id |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 428 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 429 | # Re-register for proxied messages right away |
| 430 | self.proxy_address = device.proxy_address |
| 431 | self.adapter_agent.register_for_proxied_messages( |
| 432 | device.proxy_address) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 433 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 434 | # Re-enable the ports on that device |
| 435 | self.adapter_agent.enable_all_ports(self.device_id) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 436 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 437 | # Refresh the port reference |
| 438 | self.uni_port = self._get_uni_port() |
| 439 | self.pon_port = self._get_pon_port() |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 440 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 441 | # Add the pon port reference to the parent |
| 442 | self.adapter_agent.add_port_reference_to_parent(device.id, |
| 443 | self.pon_port) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 444 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 445 | # Update the connect status to REACHABLE |
| 446 | device.connect_status = ConnectStatus.REACHABLE |
| 447 | self.adapter_agent.update_device(device) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 448 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 449 | # re-add uni port to logical device |
| 450 | parent_device = self.adapter_agent.get_device(device.parent_id) |
| 451 | logical_device_id = parent_device.parent_id |
| 452 | assert logical_device_id |
| 453 | port_no = device.proxy_address.channel_id |
| 454 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
| 455 | self.adapter_agent.add_logical_port(logical_device_id, LogicalPort( |
| 456 | id='uni-{}'.format(port_no), |
| 457 | ofp_port=ofp_port( |
| 458 | port_no=port_no, |
| 459 | hw_addr=mac_str_to_tuple('00:00:00:00:00:%02x' % port_no), |
Andy Bavier | ea82b46 | 2018-07-27 16:48:13 -0700 | [diff] [blame^] | 460 | name=device.serial_number, |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 461 | config=0, |
| 462 | state=OFPPS_LIVE, |
| 463 | curr=cap, |
| 464 | advertised=cap, |
| 465 | peer=cap, |
| 466 | curr_speed=OFPPF_1GB_FD, |
| 467 | max_speed=OFPPF_1GB_FD |
| 468 | ), |
| 469 | device_id=device.id, |
| 470 | device_port_no=self.uni_port.port_no |
| 471 | )) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 472 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 473 | device = self.adapter_agent.get_device(device.id) |
| 474 | device.oper_status = OperStatus.ACTIVE |
| 475 | self.adapter_agent.update_device(device) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 476 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 477 | self.log.info('re-enabled', device_id=device.id) |
| 478 | except Exception, e: |
| 479 | self.log.exception('error-reenabling', e=e) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 480 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 481 | def delete(self): |
| 482 | self.log.info('deleting', device_id=self.device_id) |
| 483 | |
| 484 | # A delete request may be received when an OLT is dsiabled |
| 485 | |
| 486 | # TODO: |
| 487 | # 1) Remove all flows from the device |
| 488 | # 2) Remove the device from ponsim |
| 489 | |
| 490 | self.log.info('deleted', device_id=self.device_id) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 491 | |
| 492 | def get_interface_config(self, data): |
| 493 | interfaceConfig = InterfaceConfig() |
| 494 | if isinstance(data, OntaniConfig): |
| 495 | interfaceConfig.ont_ani_config.CopyFrom(data) |
| 496 | elif isinstance(data, VOntaniConfig): |
| 497 | interfaceConfig.vont_ani_config.CopyFrom(data) |
| 498 | elif isinstance(data, VEnetConfig): |
| 499 | interfaceConfig.venet_config.CopyFrom(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 500 | elif isinstance(data, TrafficDescriptorProfileData): |
| 501 | interfaceConfig.traffic_descriptor_profile_config_data.CopyFrom( |
| 502 | data) |
| 503 | elif isinstance(data, TcontsConfigData): |
| 504 | interfaceConfig.tconts_config_data.CopyFrom(data) |
| 505 | elif isinstance(data, GemportsConfigData): |
| 506 | interfaceConfig.gemports_config_data.CopyFrom(data) |
| 507 | elif isinstance(data, MulticastGemportsConfigData): |
| 508 | interfaceConfig.multicast_gemports_config_data.CopyFrom(data) |
| 509 | elif isinstance(data, MulticastDistributionSetData): |
| 510 | interfaceConfig.multicast_distribution_set_data.CopyFrom(data) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 511 | else: |
| 512 | return None |
| 513 | return interfaceConfig |
| 514 | |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 515 | def xpon_ponsim_onu_interface(self, method_name, data, data2=None): |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 516 | interfaceConfig = self.get_interface_config(data) |
| 517 | if interfaceConfig is not None: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 518 | self.log.info('forwarding-{}-request-to-onu-for-interface-type' |
| 519 | .format(xpon_ponsim_onu_itfs[method_name]['log']), |
| 520 | interface_type=type(data)) |
| 521 | if data2 is not None: |
| 522 | self.log.info(interface_type=type(data2)) |
| 523 | |
| 524 | def create_interface(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 525 | _method_name = sys._getframe().f_code.co_name |
| 526 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 527 | |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 528 | def update_interface(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 529 | _method_name = sys._getframe().f_code.co_name |
| 530 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 531 | |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 532 | def remove_interface(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 533 | _method_name = sys._getframe().f_code.co_name |
| 534 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 535 | |
| 536 | def create_tcont(self, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 537 | _method_name = sys._getframe().f_code.co_name |
| 538 | self.xpon_ponsim_onu_interface(_method_name, tcont_data, |
| 539 | traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 540 | |
| 541 | def update_tcont(self, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 542 | _method_name = sys._getframe().f_code.co_name |
| 543 | self.xpon_ponsim_onu_interface(_method_name, tcont_data, |
| 544 | traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 545 | |
| 546 | def remove_tcont(self, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 547 | _method_name = sys._getframe().f_code.co_name |
| 548 | self.xpon_ponsim_onu_interface(_method_name, tcont_data, |
| 549 | traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 550 | |
| 551 | def create_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 552 | _method_name = sys._getframe().f_code.co_name |
| 553 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 554 | |
| 555 | def update_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 556 | _method_name = sys._getframe().f_code.co_name |
| 557 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 558 | |
| 559 | def remove_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 560 | _method_name = sys._getframe().f_code.co_name |
| 561 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 562 | |
| 563 | def create_multicast_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 564 | _method_name = sys._getframe().f_code.co_name |
| 565 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 566 | |
| 567 | def update_multicast_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 568 | _method_name = sys._getframe().f_code.co_name |
| 569 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 570 | |
| 571 | def remove_multicast_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 572 | _method_name = sys._getframe().f_code.co_name |
| 573 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 574 | |
| 575 | def create_multicast_distribution_set(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 576 | _method_name = sys._getframe().f_code.co_name |
| 577 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 578 | |
| 579 | def update_multicast_distribution_set(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 580 | _method_name = sys._getframe().f_code.co_name |
| 581 | self.xpon_ponsim_onu_interface(_method_name, data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 582 | |
| 583 | def remove_multicast_distribution_set(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 584 | _method_name = sys._getframe().f_code.co_name |
| 585 | self.xpon_ponsim_onu_interface(_method_name, data) |