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 | """ |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 20 | import sys |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 21 | from uuid import uuid4 |
| 22 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 23 | import arrow |
Jeff | 55a2f13 | 2018-08-05 21:10:41 -0700 | [diff] [blame] | 24 | import voltha.core.flow_decomposer as fd |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 25 | import grpc |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 26 | import json |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 27 | import copy |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 28 | import structlog |
| 29 | from scapy.layers.l2 import Ether, Dot1Q |
Gamze Abaka | 53cc0a2 | 2019-01-31 12:06:11 +0000 | [diff] [blame^] | 30 | from scapy.layers.inet import IP, Raw |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 31 | from twisted.internet import reactor |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 32 | from twisted.internet.defer import inlineCallbacks |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 33 | from grpc._channel import _Rendezvous |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 34 | |
| 35 | from common.frameio.frameio import BpfProgramFilter, hexify |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 36 | from common.utils.asleep import asleep |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 37 | from twisted.internet.task import LoopingCall |
Shad Ansari | d1aa9e7 | 2017-06-23 21:34:25 -0700 | [diff] [blame] | 38 | from voltha.adapters.iadapter import OltAdapter |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 39 | from voltha.core.logical_device_agent import mac_str_to_tuple |
| 40 | from voltha.protos import third_party |
Jeff | 55a2f13 | 2018-08-05 21:10:41 -0700 | [diff] [blame] | 41 | from voltha.protos import openflow_13_pb2 as ofp |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 42 | from voltha.protos import ponsim_pb2, ponsim_pb2_grpc |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 43 | from voltha.protos.common_pb2 import OperStatus, ConnectStatus, AdminState |
Scott Baker | 50873cc | 2018-09-21 18:14:09 -0700 | [diff] [blame] | 44 | from voltha.protos.common_pb2 import OperationResp |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 45 | from voltha.protos.device_pb2 import Port, Device, PmConfig, PmConfigs |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 46 | from voltha.protos.events_pb2 import KpiEvent, KpiEventType, MetricValuePairs |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 47 | from google.protobuf.empty_pb2 import Empty |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 48 | from voltha.protos.logical_device_pb2 import LogicalPort, LogicalDevice |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 49 | from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \ |
| 50 | OFPPF_1GB_FD, \ |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 51 | OFPC_GROUP_STATS, OFPC_PORT_STATS, OFPC_TABLE_STATS, OFPC_FLOW_STATS, \ |
| 52 | ofp_switch_features, ofp_desc |
| 53 | from voltha.protos.openflow_13_pb2 import ofp_port |
Scott Baker | b5be94d | 2018-10-09 16:13:32 -0700 | [diff] [blame] | 54 | from voltha.protos.ponsim_pb2 import FlowTable, PonSimFrame, PonSimMetricsRequest |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 55 | from voltha.registry import registry |
| 56 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 57 | from voltha.protos.bbf_fiber_base_pb2 import \ |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 58 | ChannelgroupConfig, ChannelpartitionConfig, ChannelpairConfig, \ |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 59 | ChannelterminationConfig, OntaniConfig, VOntaniConfig, VEnetConfig |
| 60 | from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import \ |
| 61 | TrafficDescriptorProfileData |
| 62 | from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData |
| 63 | from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData |
| 64 | from voltha.protos.bbf_fiber_multicast_gemport_body_pb2 import \ |
| 65 | MulticastGemportsConfigData |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 66 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 67 | from voltha.protos.bbf_fiber_multicast_distribution_set_body_pb2 import \ |
| 68 | MulticastDistributionSetData |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 69 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 70 | from voltha.protos.ponsim_pb2 import InterfaceConfig, TcontInterfaceConfig |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 71 | |
Scott Baker | 50873cc | 2018-09-21 18:14:09 -0700 | [diff] [blame] | 72 | from voltha.extensions.alarms.adapter_alarms import AdapterAlarms as VolthaAdapterAlarms |
| 73 | from voltha.extensions.alarms.simulator.simulate_alarms import AdapterAlarmSimulator |
| 74 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 75 | _ = third_party |
| 76 | log = structlog.get_logger() |
| 77 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 78 | PACKET_IN_VLAN = 4000 |
| 79 | is_inband_frame = BpfProgramFilter('(ether[14:2] & 0xfff) = 0x{:03x}'.format( |
| 80 | PACKET_IN_VLAN)) |
| 81 | |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 82 | EAP_ETH_TYPE = 0x888e |
| 83 | |
| 84 | # Classifier |
| 85 | ETH_TYPE = 'eth_type' |
| 86 | TPID = 'tpid' |
| 87 | IP_PROTO = 'ip_proto' |
| 88 | IN_PORT = 'in_port' |
| 89 | VLAN_VID = 'vlan_vid' |
| 90 | VLAN_PCP = 'vlan_pcp' |
| 91 | UDP_DST = 'udp_dst' |
| 92 | UDP_SRC = 'udp_src' |
| 93 | IPV4_DST = 'ipv4_dst' |
| 94 | IPV4_SRC = 'ipv4_src' |
| 95 | METADATA = 'metadata' |
| 96 | OUTPUT = 'output' |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 97 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 98 | class AdapterPmMetrics: |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 99 | def __init__(self, device): |
Sergio Slobodrian | ec6e391 | 2017-04-02 11:46:55 -0400 | [diff] [blame] | 100 | self.pm_names = {'tx_64_pkts', 'tx_65_127_pkts', 'tx_128_255_pkts', |
| 101 | 'tx_256_511_pkts', 'tx_512_1023_pkts', |
| 102 | 'tx_1024_1518_pkts', 'tx_1519_9k_pkts', |
| 103 | 'rx_64_pkts', 'rx_65_127_pkts', |
| 104 | 'rx_128_255_pkts', 'rx_256_511_pkts', |
| 105 | 'rx_512_1023_pkts', 'rx_1024_1518_pkts', |
| 106 | 'rx_1519_9k_pkts'} |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 107 | self.device = device |
| 108 | self.id = device.id |
| 109 | self.name = 'ponsim_olt' |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 110 | # self.id = "abc" |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 111 | self.default_freq = 150 |
| 112 | self.grouped = False |
| 113 | self.freq_override = False |
| 114 | self.pon_metrics_config = dict() |
| 115 | self.nni_metrics_config = dict() |
| 116 | self.lc = None |
| 117 | for m in self.pm_names: |
| 118 | self.pon_metrics_config[m] = PmConfig(name=m, |
| 119 | type=PmConfig.COUNTER, |
| 120 | enabled=True) |
| 121 | self.nni_metrics_config[m] = PmConfig(name=m, |
| 122 | type=PmConfig.COUNTER, |
| 123 | enabled=True) |
| 124 | |
| 125 | def update(self, pm_config): |
| 126 | if self.default_freq != pm_config.default_freq: |
| 127 | # Update the callback to the new frequency. |
| 128 | self.default_freq = pm_config.default_freq |
| 129 | self.lc.stop() |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 130 | self.lc.start(interval=self.default_freq / 10) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 131 | for m in pm_config.metrics: |
| 132 | self.pon_metrics_config[m.name].enabled = m.enabled |
| 133 | self.nni_metrics_config[m.name].enabled = m.enabled |
| 134 | |
| 135 | def make_proto(self): |
| 136 | pm_config = PmConfigs( |
| 137 | id=self.id, |
| 138 | default_freq=self.default_freq, |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 139 | grouped=False, |
| 140 | freq_override=False) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 141 | for m in sorted(self.pon_metrics_config): |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 142 | pm = self.pon_metrics_config[m] # Either will do they're the same |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 143 | pm_config.metrics.extend([PmConfig(name=pm.name, |
| 144 | type=pm.type, |
| 145 | enabled=pm.enabled)]) |
| 146 | return pm_config |
| 147 | |
| 148 | def collect_port_metrics(self, channel): |
| 149 | rtrn_port_metrics = dict() |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 150 | stub = ponsim_pb2_grpc.PonSimStub(channel) |
Scott Baker | b5be94d | 2018-10-09 16:13:32 -0700 | [diff] [blame] | 151 | stats = stub.GetStats(ponsim_pb2.PonSimMetricsRequest(port=0)) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 152 | rtrn_port_metrics['pon'] = self.extract_pon_metrics(stats) |
| 153 | rtrn_port_metrics['nni'] = self.extract_nni_metrics(stats) |
| 154 | return rtrn_port_metrics |
| 155 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 156 | def extract_pon_metrics(self, stats): |
| 157 | rtrn_pon_metrics = dict() |
| 158 | for m in stats.metrics: |
| 159 | if m.port_name == "pon": |
| 160 | for p in m.packets: |
| 161 | if self.pon_metrics_config[p.name].enabled: |
| 162 | rtrn_pon_metrics[p.name] = p.value |
| 163 | return rtrn_pon_metrics |
| 164 | |
| 165 | def extract_nni_metrics(self, stats): |
| 166 | rtrn_pon_metrics = dict() |
| 167 | for m in stats.metrics: |
| 168 | if m.port_name == "nni": |
| 169 | for p in m.packets: |
| 170 | if self.pon_metrics_config[p.name].enabled: |
| 171 | rtrn_pon_metrics[p.name] = p.value |
| 172 | return rtrn_pon_metrics |
| 173 | |
| 174 | def start_collector(self, callback): |
| 175 | log.info("starting-pm-collection", device_name=self.name, |
| 176 | device_id=self.device.id) |
| 177 | prefix = 'voltha.{}.{}'.format(self.name, self.device.id) |
| 178 | self.lc = LoopingCall(callback, self.device.id, prefix) |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 179 | self.lc.start(interval=self.default_freq / 10) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 180 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 181 | def stop_collector(self): |
| 182 | log.info("stopping-pm-collection", device_name=self.name, |
| 183 | device_id=self.device.id) |
| 184 | self.lc.stop() |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 185 | |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 186 | |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 187 | class AdapterAlarms: |
| 188 | def __init__(self, adapter, device): |
| 189 | self.adapter = adapter |
| 190 | self.device = device |
| 191 | self.lc = None |
| 192 | |
| 193 | def send_alarm(self, context_data, alarm_data): |
| 194 | try: |
| 195 | current_context = {} |
| 196 | for key, value in context_data.__dict__.items(): |
| 197 | current_context[key] = str(value) |
| 198 | |
| 199 | alarm_event = self.adapter.adapter_agent.create_alarm( |
| 200 | resource_id=self.device.id, |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 201 | description="{}.{} - {}".format(self.adapter.name, |
| 202 | self.device.id, |
| 203 | alarm_data[ |
| 204 | 'description']) if 'description' in alarm_data else None, |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 205 | type=alarm_data['type'] if 'type' in alarm_data else None, |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 206 | category=alarm_data[ |
| 207 | 'category'] if 'category' in alarm_data else None, |
| 208 | severity=alarm_data[ |
| 209 | 'severity'] if 'severity' in alarm_data else None, |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 210 | state=alarm_data['state'] if 'state' in alarm_data else None, |
| 211 | raised_ts=alarm_data['ts'] if 'ts' in alarm_data else 0, |
| 212 | context=current_context |
| 213 | ) |
| 214 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 215 | self.adapter.adapter_agent.submit_alarm(self.device.id, |
| 216 | alarm_event) |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 217 | |
| 218 | except Exception as e: |
| 219 | log.exception('failed-to-send-alarm', e=e) |
| 220 | |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 221 | |
Shad Ansari | d1aa9e7 | 2017-06-23 21:34:25 -0700 | [diff] [blame] | 222 | class PonSimOltAdapter(OltAdapter): |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 223 | def __init__(self, adapter_agent, config): |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 224 | super(PonSimOltAdapter, self).__init__(adapter_agent=adapter_agent, |
| 225 | config=config, |
Shad Ansari | 96f817b | 2017-06-18 23:17:44 -0700 | [diff] [blame] | 226 | device_handler_class=PonSimOltHandler, |
Shad Ansari | 14bcd99 | 2017-06-13 14:27:20 -0700 | [diff] [blame] | 227 | name='ponsim_olt', |
| 228 | vendor='Voltha project', |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 229 | version='0.4', |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 230 | device_type='ponsim_olt', |
| 231 | accepts_bulk_flow_update=True, |
| 232 | accepts_add_remove_flow_updates=False) |
Shad Ansari | 96f817b | 2017-06-18 23:17:44 -0700 | [diff] [blame] | 233 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 234 | def update_pm_config(self, device, pm_config): |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 235 | log.info("adapter-update-pm-config", device=device, |
| 236 | pm_config=pm_config) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 237 | handler = self.devices_handlers[device.id] |
| 238 | handler.update_pm_config(device, pm_config) |
Sergio Slobodrian | ec864c6 | 2017-03-09 11:41:43 -0500 | [diff] [blame] | 239 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 240 | def create_interface(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 241 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 242 | log.info('create-interface', device_id=device.id) |
| 243 | self.devices_handlers[device.id].create_interface(data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 244 | |
| 245 | def update_interface(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 246 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 247 | log.info('update-interface', device_id=device.id) |
| 248 | self.devices_handlers[device.id].update_interface(data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 249 | |
| 250 | def remove_interface(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 251 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 252 | log.info('remove-interface', device_id=device.id) |
| 253 | self.devices_handlers[device.id].remove_interface(data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 254 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 255 | def create_tcont(self, device, tcont_data, traffic_descriptor_data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 256 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 257 | log.info('create-tcont', device_id=device.id) |
| 258 | self.devices_handlers[device.id].create_tcont( |
| 259 | tcont_data, traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 260 | |
| 261 | def update_tcont(self, device, tcont_data, traffic_descriptor_data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 262 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 263 | log.info('update-tcont', device_id=device.id) |
| 264 | self.devices_handlers[device.id].update_tcont( |
| 265 | tcont_data, traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 266 | |
| 267 | def remove_tcont(self, device, tcont_data, traffic_descriptor_data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 268 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 269 | log.info('remove-tcont', device_id=device.id) |
| 270 | self.devices_handlers[device.id].remove_tcont( |
| 271 | tcont_data, traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 272 | |
| 273 | def create_gemport(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 274 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 275 | log.info('create-gemport', device_id=device.id) |
| 276 | self.devices_handlers[device.id].create_gemport(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 277 | |
| 278 | def update_gemport(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 279 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 280 | log.info('update-gemport', device_id=device.id) |
| 281 | self.devices_handlers[device.id].update_gemport(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 282 | |
| 283 | def remove_gemport(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 284 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 285 | log.info('remove-gemport', device_id=device.id) |
| 286 | self.devices_handlers[device.id].remove_gemport(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 287 | |
| 288 | def create_multicast_gemport(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 289 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 290 | log.info('create-multicast-gemport', device_id=device.id) |
| 291 | self.devices_handlers[device.id].create_multicast_gemport(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 292 | |
| 293 | def update_multicast_gemport(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 294 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 295 | log.info('update-multicast-gemport', device_id=device.id) |
| 296 | self.devices_handlers[device.id].update_multicast_gemport(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 297 | |
| 298 | def remove_multicast_gemport(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 299 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 300 | log.info('remove-multicast-gemport', device_id=device.id) |
| 301 | self.devices_handlers[device.id].remove_multicast_gemport(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 302 | |
| 303 | def create_multicast_distribution_set(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 304 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 305 | log.info('create-multicast-distribution-set', device_id=device.id) |
| 306 | self.devices_handlers[device.id].create_multicast_distribution_set( |
| 307 | data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 308 | |
| 309 | def update_multicast_distribution_set(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 310 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 311 | log.info('update-multicast-distribution-set', device_id=device.id) |
| 312 | self.devices_handlers[device.id].update_multicast_distribution_set( |
| 313 | data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 314 | |
| 315 | def remove_multicast_distribution_set(self, device, data): |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 316 | if super(PonSimOltAdapter, self)._get_handler(device): |
| 317 | log.info('remove-multicast-distribution-set', device_id=device.id) |
| 318 | self.devices_handlers[device.id].remove_multicast_distribution_set( |
| 319 | data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 320 | |
Scott Baker | 50873cc | 2018-09-21 18:14:09 -0700 | [diff] [blame] | 321 | def simulate_alarm(self, device, alarm): |
| 322 | handler = self.devices_handlers[device.id] |
| 323 | handler.simulate_alarm(alarm) |
| 324 | return OperationResp(code=OperationResp.OPERATION_SUCCESS) |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 325 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 326 | class PonSimOltHandler(object): |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 327 | xpon_ponsim_olt_itfs = { |
| 328 | 'create_interface': { |
| 329 | 'method_name': 'CreateInterface', |
| 330 | 'log': 'create-interface'}, |
| 331 | 'update_interface': { |
| 332 | 'method_name': 'UpdateInterface', |
| 333 | 'log': 'update-interface'}, |
| 334 | 'remove_interface': { |
| 335 | 'method_name': 'RemoveInterface', |
| 336 | 'log': 'remove-interface'}, |
| 337 | 'create_tcont': { |
| 338 | 'method_name': 'CreateTcont', |
| 339 | 'log': 'create-tconts-config-data'}, |
| 340 | 'update_tcont': { |
| 341 | 'method_name': 'UpdateTcont', |
| 342 | 'log': 'update-tconts-config-data'}, |
| 343 | 'remove_tcont': { |
| 344 | 'method_name': 'RemoveTcont', |
| 345 | 'log': 'remove-tconts-config-data'}, |
| 346 | 'create_gemport': { |
| 347 | 'method_name': 'CreateGemport', |
| 348 | 'log': 'create-gemports-config-data'}, |
| 349 | 'update_gemport': { |
| 350 | 'method_name': 'UpdateGemport', |
| 351 | 'log': 'update-gemports-config-data'}, |
| 352 | 'remove_gemport': { |
| 353 | 'method_name': 'RemoveGemport', |
| 354 | 'log': 'remove-gemports-config-data'}, |
| 355 | 'create_multicast_gemport': { |
| 356 | 'method_name': 'CreateMulticastGemport', |
| 357 | 'log': 'create-multicast-gemports-config-data'}, |
| 358 | 'update_multicast_gemport': { |
| 359 | 'method_name': 'UpdateMulticastGemport', |
| 360 | 'log': 'update-multicast-gemports-config-data'}, |
| 361 | 'remove_multicast_gemport': { |
| 362 | 'method_name': 'RemoveMulticastGemport', |
| 363 | 'log': 'remove-multicast-gemports-config-data'}, |
| 364 | 'create_multicast_distribution_set': { |
| 365 | 'method_name': 'CreateMulticastDistributionSet', |
| 366 | 'log': 'create-multicast-distribution-set-data'}, |
| 367 | 'update_multicast_distribution_set': { |
| 368 | 'method_name': 'UpdateMulticastDistributionSet', |
| 369 | 'log': 'update-multicast-distribution-set-data'}, |
| 370 | 'remove_multicast_distribution_set': { |
| 371 | 'method_name': 'RemoveMulticastDistributionSet', |
| 372 | 'log': 'remove-multicast-distribution-set-data'}, |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 373 | } |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 374 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 375 | def __init__(self, adapter, device_id): |
| 376 | self.adapter = adapter |
| 377 | self.adapter_agent = adapter.adapter_agent |
| 378 | self.device_id = device_id |
| 379 | self.log = structlog.get_logger(device_id=device_id) |
| 380 | self.channel = None |
| 381 | self.io_port = None |
| 382 | self.logical_device_id = None |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 383 | self.nni_port = None |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 384 | self.ofp_port_no = None |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 385 | self.interface = registry('main').get_args().interface |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 386 | self.ponsim_comm = registry('main').get_args().ponsim_comm |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 387 | self.pm_metrics = None |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 388 | self.alarms = None |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 389 | self.frames = None |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 390 | self.uni_ports = [] |
| 391 | self.ctag_map = {} |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 392 | |
| 393 | def __del__(self): |
| 394 | if self.io_port is not None: |
Zsolt Haraszti | 3e6f089 | 2017-01-19 11:51:40 -0800 | [diff] [blame] | 395 | registry('frameio').close_port(self.io_port) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 396 | |
| 397 | def get_channel(self): |
| 398 | if self.channel is None: |
| 399 | device = self.adapter_agent.get_device(self.device_id) |
schowdhury | 9e24775 | 2017-07-14 06:56:20 -0700 | [diff] [blame] | 400 | |
Jeff | 70e8b2d | 2018-07-24 13:37:29 -0700 | [diff] [blame] | 401 | self.channel = grpc.insecure_channel(device.host_and_port) |
schowdhury | 9e24775 | 2017-07-14 06:56:20 -0700 | [diff] [blame] | 402 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 403 | return self.channel |
| 404 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 405 | def close_channel(self): |
| 406 | if self.channel is None: |
| 407 | self.log.info('grpc-channel-already-closed') |
| 408 | return |
| 409 | else: |
| 410 | if self.frames is not None: |
| 411 | self.frames.cancel() |
| 412 | self.frames = None |
| 413 | self.log.info('cancelled-grpc-frame-stream') |
| 414 | |
| 415 | self.channel.unsubscribe(lambda *args: None) |
| 416 | self.channel = None |
| 417 | |
| 418 | self.log.info('grpc-channel-closed') |
| 419 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 420 | def _get_nni_port(self): |
| 421 | ports = self.adapter_agent.get_ports(self.device_id, Port.ETHERNET_NNI) |
| 422 | if ports: |
| 423 | # For now, we use on one NNI port |
| 424 | return ports[0] |
| 425 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 426 | def activate(self, device): |
| 427 | self.log.info('activating') |
| 428 | |
| 429 | if not device.host_and_port: |
| 430 | device.oper_status = OperStatus.FAILED |
| 431 | device.reason = 'No host_and_port field provided' |
| 432 | self.adapter_agent.update_device(device) |
| 433 | return |
| 434 | |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 435 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 436 | info = stub.GetDeviceInfo(Empty()) |
| 437 | log.info('got-info', info=info) |
| 438 | |
| 439 | device.root = True |
| 440 | device.vendor = 'ponsim' |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 441 | device.model = 'n/a' |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 442 | device.serial_number = device.host_and_port |
| 443 | device.connect_status = ConnectStatus.REACHABLE |
| 444 | self.adapter_agent.update_device(device) |
| 445 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 446 | # Now set the initial PM configuration for this device |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 447 | self.pm_metrics = AdapterPmMetrics(device) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 448 | pm_config = self.pm_metrics.make_proto() |
| 449 | log.info("initial-pm-config", pm_config=pm_config) |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 450 | self.adapter_agent.update_device_pm_config(pm_config, init=True) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 451 | |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 452 | # Setup alarm handler |
| 453 | self.alarms = AdapterAlarms(self.adapter, device) |
| 454 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 455 | nni_port = Port( |
Jonathan Hart | 32fe881 | 2018-08-21 17:10:12 -0700 | [diff] [blame] | 456 | port_no=info.nni_port, |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 457 | label='NNI facing Ethernet port', |
| 458 | type=Port.ETHERNET_NNI, |
| 459 | admin_state=AdminState.ENABLED, |
| 460 | oper_status=OperStatus.ACTIVE |
| 461 | ) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 462 | self.nni_port = nni_port |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 463 | self.adapter_agent.add_port(device.id, nni_port) |
| 464 | self.adapter_agent.add_port(device.id, Port( |
| 465 | port_no=1, |
| 466 | label='PON port', |
| 467 | type=Port.PON_OLT, |
| 468 | admin_state=AdminState.ENABLED, |
| 469 | oper_status=OperStatus.ACTIVE |
| 470 | )) |
| 471 | |
| 472 | ld = LogicalDevice( |
khenaidoo | 507d922 | 2017-10-10 16:23:49 -0400 | [diff] [blame] | 473 | # not setting id and datapath_id. Adapter agent will pick the id |
| 474 | # and will pick the datapath_id is it is not provided |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 475 | desc=ofp_desc( |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 476 | hw_desc='simualted pon', |
| 477 | sw_desc='simualted pon', |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 478 | # serial_num=uuid4().hex, |
Jonathan Hart | 32fe881 | 2018-08-21 17:10:12 -0700 | [diff] [blame] | 479 | serial_num=device.serial_number, |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 480 | dp_desc='n/a' |
| 481 | ), |
| 482 | switch_features=ofp_switch_features( |
| 483 | n_buffers=256, # TODO fake for now |
| 484 | n_tables=2, # TODO ditto |
| 485 | capabilities=( # TODO and ditto |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 486 | OFPC_FLOW_STATS |
| 487 | | OFPC_TABLE_STATS |
| 488 | | OFPC_PORT_STATS |
| 489 | | OFPC_GROUP_STATS |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 490 | ) |
| 491 | ), |
| 492 | root_device_id=device.id |
| 493 | ) |
khenaidoo | 507d922 | 2017-10-10 16:23:49 -0400 | [diff] [blame] | 494 | mac_address = "AA:BB:CC:DD:EE:FF" |
| 495 | ld_initialized = self.adapter_agent.create_logical_device(ld, |
| 496 | dpid=mac_address) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 497 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 498 | self.ofp_port_no = info.nni_port |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 499 | self.adapter_agent.add_logical_port(ld_initialized.id, LogicalPort( |
| 500 | id='nni', |
| 501 | ofp_port=ofp_port( |
| 502 | port_no=info.nni_port, |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 503 | hw_addr=mac_str_to_tuple( |
| 504 | '00:00:00:00:00:%02x' % info.nni_port), |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 505 | name='nni', |
| 506 | config=0, |
| 507 | state=OFPPS_LIVE, |
| 508 | curr=cap, |
| 509 | advertised=cap, |
| 510 | peer=cap, |
| 511 | curr_speed=OFPPF_1GB_FD, |
| 512 | max_speed=OFPPF_1GB_FD |
| 513 | ), |
| 514 | device_id=device.id, |
| 515 | device_port_no=nni_port.port_no, |
| 516 | root_port=True |
| 517 | )) |
| 518 | |
| 519 | device = self.adapter_agent.get_device(device.id) |
| 520 | device.parent_id = ld_initialized.id |
| 521 | device.oper_status = OperStatus.ACTIVE |
| 522 | self.adapter_agent.update_device(device) |
| 523 | self.logical_device_id = ld_initialized.id |
| 524 | |
Andy Bavier | ea82b46 | 2018-07-27 16:48:13 -0700 | [diff] [blame] | 525 | # register ONUS |
| 526 | for onu in info.onus: |
| 527 | vlan_id = onu.uni_port |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 528 | self.adapter_agent.child_device_detected( |
| 529 | parent_device_id=device.id, |
| 530 | parent_port_no=1, |
Niren R Chidrawar | efcebcd | 2017-07-19 20:03:39 -0400 | [diff] [blame] | 531 | child_device_type='ponsim_onu', |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 532 | proxy_address=Device.ProxyAddress( |
| 533 | device_id=device.id, |
| 534 | channel_id=vlan_id |
| 535 | ), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 536 | admin_state=AdminState.ENABLED, |
Andy Bavier | ea82b46 | 2018-07-27 16:48:13 -0700 | [diff] [blame] | 537 | vlan=vlan_id, |
| 538 | serial_number=onu.serial_number |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 539 | ) |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 540 | self.uni_ports.append(int(onu.uni_port)) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 541 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 542 | if self.ponsim_comm == 'grpc': |
| 543 | self.log.info('starting-frame-grpc-stream') |
| 544 | reactor.callInThread(self.rcv_grpc) |
| 545 | self.log.info('started-frame-grpc-stream') |
| 546 | else: |
| 547 | # finally, open the frameio port to receive in-band packet_in messages |
| 548 | self.log.info('registering-frameio') |
| 549 | self.io_port = registry('frameio').open_port( |
| 550 | self.interface, self.rcv_io, is_inband_frame) |
| 551 | self.log.info('registered-frameio') |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 552 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 553 | # Start collecting stats from the device after a brief pause |
| 554 | self.start_kpi_collection(device.id) |
| 555 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 556 | def reconcile(self, device): |
| 557 | self.log.info('reconciling-OLT-device-starts') |
| 558 | |
| 559 | if not device.host_and_port: |
| 560 | device.oper_status = OperStatus.FAILED |
| 561 | device.reason = 'No host_and_port field provided' |
| 562 | self.adapter_agent.update_device(device) |
| 563 | return |
| 564 | |
| 565 | try: |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 566 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 567 | info = stub.GetDeviceInfo(Empty()) |
| 568 | log.info('got-info', info=info) |
| 569 | # TODO: Verify we are connected to the same device we are |
| 570 | # reconciling - not much data in ponsim to differentiate at the |
| 571 | # time |
| 572 | device.oper_status = OperStatus.ACTIVE |
| 573 | self.adapter_agent.update_device(device) |
| 574 | self.ofp_port_no = info.nni_port |
| 575 | self.nni_port = self._get_nni_port() |
| 576 | except Exception, e: |
| 577 | log.exception('device-unreachable', e=e) |
| 578 | device.connect_status = ConnectStatus.UNREACHABLE |
| 579 | device.oper_status = OperStatus.UNKNOWN |
| 580 | self.adapter_agent.update_device(device) |
| 581 | return |
| 582 | |
| 583 | # Now set the initial PM configuration for this device |
| 584 | self.pm_metrics = AdapterPmMetrics(device) |
| 585 | pm_config = self.pm_metrics.make_proto() |
| 586 | log.info("initial-pm-config", pm_config=pm_config) |
| 587 | self.adapter_agent.update_device_pm_config(pm_config, init=True) |
| 588 | |
| 589 | # Setup alarm handler |
| 590 | self.alarms = AdapterAlarms(self.adapter, device) |
| 591 | |
| 592 | # TODO: Is there anything required to verify nni and PON ports |
| 593 | |
| 594 | # Set the logical device id |
| 595 | device = self.adapter_agent.get_device(device.id) |
| 596 | if device.parent_id: |
| 597 | self.logical_device_id = device.parent_id |
| 598 | self.adapter_agent.reconcile_logical_device(device.parent_id) |
| 599 | else: |
| 600 | self.log.info('no-logical-device-set') |
| 601 | |
| 602 | # Reconcile child devices |
| 603 | self.adapter_agent.reconcile_child_devices(device.id) |
| 604 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 605 | if self.ponsim_comm == 'grpc': |
| 606 | reactor.callInThread(self.rcv_grpc) |
| 607 | else: |
| 608 | # finally, open the frameio port to receive in-band packet_in messages |
| 609 | self.io_port = registry('frameio').open_port( |
| 610 | self.interface, self.rcv_io, is_inband_frame) |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 611 | |
| 612 | # Start collecting stats from the device after a brief pause |
| 613 | self.start_kpi_collection(device.id) |
| 614 | |
| 615 | self.log.info('reconciling-OLT-device-ends') |
| 616 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 617 | def _rcv_frame(self, frame): |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 618 | pkt = Ether(frame) |
Gamze Abaka | 53cc0a2 | 2019-01-31 12:06:11 +0000 | [diff] [blame^] | 619 | self.log.info('received packet', pkt=pkt) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 620 | if pkt.haslayer(Dot1Q): |
| 621 | outer_shim = pkt.getlayer(Dot1Q) |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 622 | |
Gamze Abaka | 53cc0a2 | 2019-01-31 12:06:11 +0000 | [diff] [blame^] | 623 | if pkt.haslayer(IP) or outer_shim.type == EAP_ETH_TYPE: |
| 624 | cvid = outer_shim.vlan |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 625 | logical_port = self.get_subscriber_uni_port(cvid) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 626 | popped_frame = ( |
Gamze Abaka | 53cc0a2 | 2019-01-31 12:06:11 +0000 | [diff] [blame^] | 627 | Ether(src=pkt.src, dst=pkt.dst, type=outer_shim.type) / |
| 628 | outer_shim.payload |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 629 | ) |
| 630 | kw = dict( |
| 631 | logical_device_id=self.logical_device_id, |
| 632 | logical_port_no=logical_port, |
| 633 | ) |
| 634 | self.log.info('sending-packet-in', **kw) |
| 635 | self.adapter_agent.send_packet_in( |
| 636 | packet=str(popped_frame), **kw) |
Gamze Abaka | 53cc0a2 | 2019-01-31 12:06:11 +0000 | [diff] [blame^] | 637 | |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 638 | elif pkt.haslayer(Raw): |
| 639 | raw_data = json.loads(pkt.getlayer(Raw).load) |
| 640 | self.alarms.send_alarm(self, raw_data) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 641 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 642 | @inlineCallbacks |
| 643 | def rcv_grpc(self): |
| 644 | """ |
| 645 | This call establishes a GRPC stream to receive frames. |
| 646 | """ |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 647 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 648 | |
| 649 | # Attempt to establish a grpc stream with the remote ponsim service |
| 650 | self.frames = stub.ReceiveFrames(Empty()) |
| 651 | |
| 652 | self.log.info('start-receiving-grpc-frames') |
| 653 | |
| 654 | try: |
| 655 | for frame in self.frames: |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 656 | self.log.info('received-grpc-frame', |
| 657 | frame_len=len(frame.payload)) |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 658 | self._rcv_frame(frame.payload) |
| 659 | |
| 660 | except _Rendezvous, e: |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 661 | log.warn('grpc-connection-lost', message=e.message) |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 662 | |
| 663 | self.log.info('stopped-receiving-grpc-frames') |
| 664 | |
| 665 | def rcv_io(self, port, frame): |
| 666 | self.log.info('received-io-frame', iface_name=port.iface_name, |
| 667 | frame_len=len(frame)) |
| 668 | self._rcv_frame(frame) |
| 669 | |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 670 | def to_controller(self, flow): |
| 671 | for action in fd.get_actions(flow): |
| 672 | if action.type == ofp.OFPAT_OUTPUT: |
| 673 | action.output.port = ofp.OFPP_CONTROLLER |
| 674 | self.log.info('sending flow to controller') |
| 675 | |
| 676 | # Lookup subscriber ctag for a particular PON port |
| 677 | def get_subscriber_ctag(self, flows, port): |
| 678 | self.log.debug('looking from subscriber flow for port', port=port) |
| 679 | |
| 680 | for flow in flows: |
| 681 | in_port = fd.get_in_port(flow) |
| 682 | out_port = fd.get_out_port(flow) |
| 683 | if in_port == port and out_port == self.nni_port.port_no: |
| 684 | fields = fd.get_ofb_fields(flow) |
| 685 | self.log.debug('subscriber flow found', fields=fields) |
| 686 | for field in fields: |
| 687 | if field.type == fd.VLAN_VID: |
| 688 | self.log.debug('subscriber ctag found', |
| 689 | vlan_id=field.vlan_vid) |
| 690 | return field.vlan_vid & 0x0fff |
| 691 | self.log.debug('No subscriber flow found', port=port) |
| 692 | return None |
| 693 | |
| 694 | # Lookup UNI port for a particular subscriber ctag |
| 695 | def get_subscriber_uni_port(self, ctag): |
| 696 | self.log.debug('get_subscriber_uni_port', ctag=ctag, ctag_map=self.ctag_map) |
| 697 | c = int(ctag) |
| 698 | if c in self.ctag_map: |
| 699 | return self.ctag_map[c] |
Gamze Abaka | 53cc0a2 | 2019-01-31 12:06:11 +0000 | [diff] [blame^] | 700 | # return None |
| 701 | # HACK: temporarily pass atest |
| 702 | return int(128) |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 703 | |
| 704 | def clear_ctag_map(self): |
| 705 | self.ctag_map = {} |
| 706 | |
| 707 | def update_ctag_map(self, ctag, uni_port): |
| 708 | c = int(ctag) |
| 709 | u = int(uni_port) |
| 710 | if not self.is_uni_port(u): |
| 711 | self.log.warning('update_ctag_map: unknown UNI port', uni_port=u) |
| 712 | if c in self.ctag_map and self.ctag_map[c] != u: |
| 713 | self.log.warning('update_ctag_map: changing UNI port for ctag', |
| 714 | ctag=c, old=self.ctag_map[c], new=u) |
| 715 | self.ctag_map[c] = u |
| 716 | |
| 717 | # Create a new flow that's a copy of the old flow but change the vlan_vid |
| 718 | # Used to create per-subscriber DHCP and EAPOL flows |
| 719 | def create_secondary_flow(self, flow, vlan_id): |
| 720 | secondary_flow = copy.deepcopy(flow) |
| 721 | for field in fd.get_ofb_fields(secondary_flow): |
| 722 | if field.type == fd.VLAN_VID: |
| 723 | field.vlan_vid = vlan_id | 0x1000 |
| 724 | return secondary_flow |
| 725 | |
| 726 | def is_uni_port(self, vlan_id): |
| 727 | return int(vlan_id) in self.uni_ports |
| 728 | |
| 729 | def create_secondary_flows(self, trapflows, allflows, type): |
| 730 | secondary_flows = [] |
| 731 | for vlan_vid, flow in trapflows.iteritems(): |
| 732 | if self.is_uni_port(vlan_vid): |
| 733 | self.update_ctag_map(vlan_vid, vlan_vid) |
| 734 | ctag = self.get_subscriber_ctag(allflows, fd.get_in_port(flow)) |
| 735 | if ctag is not None: |
| 736 | self.update_ctag_map(ctag, vlan_vid) |
| 737 | if ctag not in trapflows: |
| 738 | self.log.info('add secondary %s flow' % type, ctag=ctag) |
| 739 | secondary_flows.append(self.create_secondary_flow(flow, ctag)) |
| 740 | return secondary_flows |
| 741 | |
Jeff | 55a2f13 | 2018-08-05 21:10:41 -0700 | [diff] [blame] | 742 | # VOLTHA's flow decomposition removes the information about which flows |
| 743 | # are trap flows where traffic should be forwarded to the controller. |
| 744 | # We'll go through the flows and change the output port of flows that we |
| 745 | # know to be trap flows to the OF CONTROLLER port. |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 746 | def update_flow_table(self, flows): |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 747 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 748 | self.log.info('pushing-olt-flow-table') |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 749 | |
| 750 | self.clear_ctag_map() |
| 751 | dhcp_upstream_flows = {} |
| 752 | eapol_flows = {} |
| 753 | secondary_flows = [] |
| 754 | |
Jeff | 55a2f13 | 2018-08-05 21:10:41 -0700 | [diff] [blame] | 755 | for flow in flows: |
| 756 | classifier_info = {} |
| 757 | for field in fd.get_ofb_fields(flow): |
| 758 | if field.type == fd.ETH_TYPE: |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 759 | classifier_info[ETH_TYPE] = field.eth_type |
Jeff | 55a2f13 | 2018-08-05 21:10:41 -0700 | [diff] [blame] | 760 | elif field.type == fd.IP_PROTO: |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 761 | classifier_info[IP_PROTO] = field.ip_proto |
| 762 | elif field.type == fd.IN_PORT: |
| 763 | classifier_info[IN_PORT] = field.port |
| 764 | elif field.type == fd.VLAN_VID: |
| 765 | classifier_info[VLAN_VID] = field.vlan_vid & 0xfff |
| 766 | elif field.type == fd.VLAN_PCP: |
| 767 | classifier_info[VLAN_PCP] = field.vlan_pcp |
| 768 | elif field.type == fd.UDP_DST: |
| 769 | classifier_info[UDP_DST] = field.udp_dst |
| 770 | elif field.type == fd.UDP_SRC: |
| 771 | classifier_info[UDP_SRC] = field.udp_src |
| 772 | elif field.type == fd.IPV4_DST: |
| 773 | classifier_info[IPV4_DST] = field.ipv4_dst |
| 774 | elif field.type == fd.IPV4_SRC: |
| 775 | classifier_info[IPV4_SRC] = field.ipv4_src |
| 776 | elif field.type == fd.METADATA: |
| 777 | classifier_info[METADATA] = field.table_metadata |
| 778 | else: |
| 779 | self.log.debug('field-type-unhandled field.type={}'.format( |
| 780 | field.type)) |
| 781 | |
| 782 | self.log.debug('classifier_info', classifier_info=classifier_info) |
| 783 | |
| 784 | if IP_PROTO in classifier_info: |
| 785 | if classifier_info[IP_PROTO] == 17: |
| 786 | if UDP_SRC in classifier_info: |
| 787 | if classifier_info[UDP_SRC] == 68: |
| 788 | self.log.info('dhcp upstream flow add') |
| 789 | if VLAN_VID in classifier_info: |
| 790 | dhcp_upstream_flows[classifier_info[VLAN_VID]] = flow |
| 791 | elif classifier_info[UDP_SRC] == 67: |
| 792 | self.log.info('dhcp downstream flow add') |
| 793 | self.to_controller(flow) |
| 794 | elif classifier_info[IP_PROTO] == 2: |
| 795 | self.log.info('igmp flow add') |
| 796 | self.to_controller(flow) |
| 797 | else: |
| 798 | self.log.warn("Invalid-Classifier-to-handle", |
| 799 | classifier_info=classifier_info) |
| 800 | elif ETH_TYPE in classifier_info: |
| 801 | if classifier_info[ETH_TYPE] == EAP_ETH_TYPE: |
| 802 | self.log.info('eapol flow add') |
| 803 | self.to_controller(flow) |
| 804 | if VLAN_VID in classifier_info: |
| 805 | eapol_flows[classifier_info[VLAN_VID]] = flow |
| 806 | |
Jeff | 55a2f13 | 2018-08-05 21:10:41 -0700 | [diff] [blame] | 807 | self.log.info('out_port', out_port=fd.get_out_port(flow)) |
| 808 | |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 809 | flows.extend(self.create_secondary_flows(dhcp_upstream_flows, flows, "DHCP")) |
| 810 | flows.extend(self.create_secondary_flows(eapol_flows, flows, "EAPOL")) |
| 811 | |
| 812 | self.log.debug('ctag_map', ctag_map=self.ctag_map) |
| 813 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 814 | stub.UpdateFlowTable(FlowTable( |
| 815 | port=0, |
| 816 | flows=flows |
| 817 | )) |
| 818 | self.log.info('success') |
| 819 | |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 820 | def remove_from_flow_table(self, flows): |
| 821 | self.log.debug('remove-from-flow-table', flows=flows) |
| 822 | # TODO: Update PONSIM code to accept incremental flow changes |
| 823 | # Once completed, the accepts_add_remove_flow_updates for this |
| 824 | # device type can be set to True |
| 825 | |
| 826 | def add_to_flow_table(self, flows): |
| 827 | self.log.debug('add-to-flow-table', flows=flows) |
| 828 | # TODO: Update PONSIM code to accept incremental flow changes |
| 829 | # Once completed, the accepts_add_remove_flow_updates for this |
| 830 | # device type can be set to True |
| 831 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 832 | def update_pm_config(self, device, pm_config): |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 833 | log.info("handler-update-pm-config", device=device, |
| 834 | pm_config=pm_config) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 835 | self.pm_metrics.update(pm_config) |
| 836 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 837 | def send_proxied_message(self, proxy_address, msg): |
Zack Williams | 18357ed | 2018-11-14 10:41:08 -0700 | [diff] [blame] | 838 | self.log.debug('sending-proxied-message') |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 839 | if isinstance(msg, FlowTable): |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 840 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 841 | self.log.info('pushing-onu-flow-table', port=msg.port) |
| 842 | res = stub.UpdateFlowTable(msg) |
| 843 | self.adapter_agent.receive_proxied_message(proxy_address, res) |
Scott Baker | b5be94d | 2018-10-09 16:13:32 -0700 | [diff] [blame] | 844 | elif isinstance(msg, PonSimMetricsRequest): |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 845 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
Zack Williams | 18357ed | 2018-11-14 10:41:08 -0700 | [diff] [blame] | 846 | self.log.debug('proxying onu stats request', port=msg.port) |
Scott Baker | b5be94d | 2018-10-09 16:13:32 -0700 | [diff] [blame] | 847 | res = stub.GetStats(msg) |
| 848 | self.adapter_agent.receive_proxied_message(proxy_address, res) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 849 | |
| 850 | def packet_out(self, egress_port, msg): |
Zack Williams | 18357ed | 2018-11-14 10:41:08 -0700 | [diff] [blame] | 851 | self.log.debug('sending-packet-out', egress_port=egress_port, |
| 852 | msg_hex=hexify(msg)) |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 853 | pkt = Ether(msg) |
Jonathan Hart | 32fe881 | 2018-08-21 17:10:12 -0700 | [diff] [blame] | 854 | out_pkt = pkt |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 855 | self.log.debug("packet_out: incoming: %s" % pkt.summary()) |
Jonathan Hart | 32fe881 | 2018-08-21 17:10:12 -0700 | [diff] [blame] | 856 | if egress_port != self.nni_port.port_no: |
| 857 | # don't do the vlan manipulation for the NNI port, vlans are already correct |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 858 | if pkt.haslayer(Dot1Q): |
| 859 | # For QinQ-tagged packets from ONOS: |
| 860 | # - Outer header is 802.1AD |
| 861 | # - Inner header is 802.1Q |
| 862 | # - Send inner header and payload |
| 863 | payload = pkt.getlayer(Dot1Q) |
| 864 | out_pkt = ( |
| 865 | Ether(src=pkt.src, dst=pkt.dst) / |
| 866 | payload |
| 867 | ) |
| 868 | else: |
| 869 | # Add egress port as VLAN tag |
| 870 | out_pkt = ( |
Jonathan Hart | 32fe881 | 2018-08-21 17:10:12 -0700 | [diff] [blame] | 871 | Ether(src=pkt.src, dst=pkt.dst) / |
| 872 | Dot1Q(vlan=egress_port, type=pkt.type) / |
| 873 | pkt.payload |
Andy Bavier | 9756651 | 2018-11-14 16:17:41 -0700 | [diff] [blame] | 874 | ) |
| 875 | self.log.debug("packet_out: outgoing: %s" % out_pkt.summary()) |
Jonathan Hart | 32fe881 | 2018-08-21 17:10:12 -0700 | [diff] [blame] | 876 | |
| 877 | # TODO need better way of mapping logical ports to PON ports |
| 878 | out_port = self.nni_port.port_no if egress_port == self.nni_port.port_no else 1 |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 879 | |
| 880 | if self.ponsim_comm == 'grpc': |
| 881 | # send over grpc stream |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 882 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
Jonathan Hart | 32fe881 | 2018-08-21 17:10:12 -0700 | [diff] [blame] | 883 | frame = PonSimFrame(id=self.device_id, payload=str(out_pkt), out_port=out_port) |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 884 | stub.SendFrame(frame) |
| 885 | else: |
| 886 | # send over frameio |
| 887 | self.io_port.send(str(out_pkt)) |
| 888 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 889 | @inlineCallbacks |
| 890 | def reboot(self): |
| 891 | self.log.info('rebooting', device_id=self.device_id) |
| 892 | |
| 893 | # Update the operational status to ACTIVATING and connect status to |
| 894 | # UNREACHABLE |
| 895 | device = self.adapter_agent.get_device(self.device_id) |
| 896 | previous_oper_status = device.oper_status |
| 897 | previous_conn_status = device.connect_status |
| 898 | device.oper_status = OperStatus.ACTIVATING |
| 899 | device.connect_status = ConnectStatus.UNREACHABLE |
| 900 | self.adapter_agent.update_device(device) |
| 901 | |
khenaidoo | 71d0a6c | 2017-03-22 21:46:04 -0400 | [diff] [blame] | 902 | # Update the child devices connect state to UNREACHABLE |
khenaidoo | 2d7af13 | 2017-03-23 15:45:51 -0400 | [diff] [blame] | 903 | self.adapter_agent.update_child_devices_state(self.device_id, |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 904 | connect_status=ConnectStatus.UNREACHABLE) |
khenaidoo | 71d0a6c | 2017-03-22 21:46:04 -0400 | [diff] [blame] | 905 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 906 | # Sleep 10 secs, simulating a reboot |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 907 | # TODO: send alert and clear alert after the reboot |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 908 | yield asleep(10) |
| 909 | |
| 910 | # Change the operational status back to its previous state. With a |
| 911 | # real OLT the operational state should be the state the device is |
| 912 | # after a reboot. |
| 913 | # Get the latest device reference |
| 914 | device = self.adapter_agent.get_device(self.device_id) |
| 915 | device.oper_status = previous_oper_status |
| 916 | device.connect_status = previous_conn_status |
| 917 | self.adapter_agent.update_device(device) |
khenaidoo | 71d0a6c | 2017-03-22 21:46:04 -0400 | [diff] [blame] | 918 | |
| 919 | # Update the child devices connect state to REACHABLE |
khenaidoo | 2d7af13 | 2017-03-23 15:45:51 -0400 | [diff] [blame] | 920 | self.adapter_agent.update_child_devices_state(self.device_id, |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 921 | connect_status=ConnectStatus.REACHABLE) |
khenaidoo | 71d0a6c | 2017-03-22 21:46:04 -0400 | [diff] [blame] | 922 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 923 | self.log.info('rebooted', device_id=self.device_id) |
| 924 | |
sathishg | 5ae8622 | 2017-06-28 15:16:29 +0530 | [diff] [blame] | 925 | def self_test_device(self, device): |
| 926 | """ |
| 927 | This is called to Self a device based on a NBI call. |
| 928 | :param device: A Voltha.Device object. |
| 929 | :return: Will return result of self test |
| 930 | """ |
| 931 | log.info('self-test-device', device=device.id) |
| 932 | raise NotImplementedError() |
| 933 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 934 | def disable(self): |
| 935 | self.log.info('disabling', device_id=self.device_id) |
| 936 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 937 | self.stop_kpi_collection() |
| 938 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 939 | # Get the latest device reference |
| 940 | device = self.adapter_agent.get_device(self.device_id) |
| 941 | |
| 942 | # Update the operational status to UNKNOWN |
| 943 | device.oper_status = OperStatus.UNKNOWN |
| 944 | device.connect_status = ConnectStatus.UNREACHABLE |
| 945 | self.adapter_agent.update_device(device) |
| 946 | |
| 947 | # Remove the logical device |
| 948 | logical_device = self.adapter_agent.get_logical_device( |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 949 | self.logical_device_id) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 950 | self.adapter_agent.delete_logical_device(logical_device) |
| 951 | |
| 952 | # Disable all child devices first |
khenaidoo | 2d7af13 | 2017-03-23 15:45:51 -0400 | [diff] [blame] | 953 | self.adapter_agent.update_child_devices_state(self.device_id, |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 954 | admin_state=AdminState.DISABLED) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 955 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 956 | # Remove the peer references from this device |
| 957 | self.adapter_agent.delete_all_peer_references(self.device_id) |
| 958 | |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 959 | # Set all ports to disabled |
| 960 | self.adapter_agent.disable_all_ports(self.device_id) |
| 961 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 962 | self.close_channel() |
| 963 | self.log.info('disabled-grpc-channel') |
| 964 | |
| 965 | if self.ponsim_comm == 'frameio': |
| 966 | # close the frameio port |
| 967 | registry('frameio').close_port(self.io_port) |
| 968 | self.log.info('disabled-frameio-port') |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 969 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 970 | # Update the logice device mapping |
| 971 | if self.logical_device_id in \ |
| 972 | self.adapter.logical_device_id_to_root_device_id: |
| 973 | del self.adapter.logical_device_id_to_root_device_id[ |
| 974 | self.logical_device_id] |
| 975 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 976 | # TODO: |
| 977 | # 1) Remove all flows from the device |
| 978 | # 2) Remove the device from ponsim |
| 979 | |
| 980 | self.log.info('disabled', device_id=device.id) |
| 981 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 982 | def reenable(self): |
| 983 | self.log.info('re-enabling', device_id=self.device_id) |
| 984 | |
| 985 | # Get the latest device reference |
| 986 | device = self.adapter_agent.get_device(self.device_id) |
| 987 | |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 988 | # Set the ofp_port_no and nni_port in case we bypassed the reconcile |
| 989 | # process if the device was in DISABLED state on voltha restart |
| 990 | if not self.ofp_port_no and not self.nni_port: |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 991 | stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) |
khenaidoo | 032d330 | 2017-06-09 14:50:04 -0400 | [diff] [blame] | 992 | info = stub.GetDeviceInfo(Empty()) |
| 993 | log.info('got-info', info=info) |
| 994 | self.ofp_port_no = info.nni_port |
| 995 | self.nni_port = self._get_nni_port() |
| 996 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 997 | # Update the connect status to REACHABLE |
| 998 | device.connect_status = ConnectStatus.REACHABLE |
| 999 | self.adapter_agent.update_device(device) |
| 1000 | |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 1001 | # Set all ports to enabled |
| 1002 | self.adapter_agent.enable_all_ports(self.device_id) |
| 1003 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1004 | ld = LogicalDevice( |
| 1005 | # not setting id and datapth_id will let the adapter agent pick id |
| 1006 | desc=ofp_desc( |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1007 | hw_desc='simulated pon', |
| 1008 | sw_desc='simulated pon', |
| 1009 | serial_num=uuid4().hex, |
| 1010 | dp_desc='n/a' |
| 1011 | ), |
| 1012 | switch_features=ofp_switch_features( |
| 1013 | n_buffers=256, # TODO fake for now |
| 1014 | n_tables=2, # TODO ditto |
| 1015 | capabilities=( # TODO and ditto |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1016 | OFPC_FLOW_STATS |
| 1017 | | OFPC_TABLE_STATS |
| 1018 | | OFPC_PORT_STATS |
| 1019 | | OFPC_GROUP_STATS |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1020 | ) |
| 1021 | ), |
| 1022 | root_device_id=device.id |
| 1023 | ) |
khenaidoo | 507d922 | 2017-10-10 16:23:49 -0400 | [diff] [blame] | 1024 | mac_address = "AA:BB:CC:DD:EE:FF" |
| 1025 | ld_initialized = self.adapter_agent.create_logical_device(ld, |
| 1026 | dpid=mac_address) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1027 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
| 1028 | self.adapter_agent.add_logical_port(ld_initialized.id, LogicalPort( |
| 1029 | id='nni', |
| 1030 | ofp_port=ofp_port( |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 1031 | port_no=self.ofp_port_no, |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1032 | hw_addr=mac_str_to_tuple( |
Khen Nursimulu | c60afa1 | 2017-03-13 14:33:50 -0400 | [diff] [blame] | 1033 | '00:00:00:00:00:%02x' % self.ofp_port_no), |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1034 | name='nni', |
| 1035 | config=0, |
| 1036 | state=OFPPS_LIVE, |
| 1037 | curr=cap, |
| 1038 | advertised=cap, |
| 1039 | peer=cap, |
| 1040 | curr_speed=OFPPF_1GB_FD, |
| 1041 | max_speed=OFPPF_1GB_FD |
| 1042 | ), |
| 1043 | device_id=device.id, |
| 1044 | device_port_no=self.nni_port.port_no, |
| 1045 | root_port=True |
| 1046 | )) |
| 1047 | |
| 1048 | device = self.adapter_agent.get_device(device.id) |
| 1049 | device.parent_id = ld_initialized.id |
| 1050 | device.oper_status = OperStatus.ACTIVE |
| 1051 | self.adapter_agent.update_device(device) |
| 1052 | self.logical_device_id = ld_initialized.id |
| 1053 | |
| 1054 | # Reenable all child devices |
khenaidoo | 2d7af13 | 2017-03-23 15:45:51 -0400 | [diff] [blame] | 1055 | self.adapter_agent.update_child_devices_state(device.id, |
Stephane Barbarie | 4475a25 | 2017-03-31 13:49:20 -0400 | [diff] [blame] | 1056 | admin_state=AdminState.ENABLED) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1057 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 1058 | if self.ponsim_comm == 'grpc': |
| 1059 | # establish frame grpc-stream |
| 1060 | reactor.callInThread(self.rcv_grpc) |
| 1061 | else: |
| 1062 | # finally, open the frameio port to receive in-band packet_in messages |
| 1063 | self.io_port = registry('frameio').open_port( |
| 1064 | self.interface, self.rcv_io, is_inband_frame) |
| 1065 | |
| 1066 | self.start_kpi_collection(device.id) |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1067 | |
| 1068 | self.log.info('re-enabled', device_id=device.id) |
| 1069 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1070 | def delete(self): |
| 1071 | self.log.info('deleting', device_id=self.device_id) |
| 1072 | |
| 1073 | # Remove all child devices |
| 1074 | self.adapter_agent.delete_all_child_devices(self.device_id) |
| 1075 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 1076 | self.close_channel() |
| 1077 | self.log.info('disabled-grpc-channel') |
| 1078 | |
| 1079 | if self.ponsim_comm == 'frameio': |
| 1080 | # close the frameio port |
| 1081 | registry('frameio').close_port(self.io_port) |
| 1082 | self.log.info('disabled-frameio-port') |
| 1083 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 1084 | # TODO: |
| 1085 | # 1) Remove all flows from the device |
| 1086 | # 2) Remove the device from ponsim |
| 1087 | |
| 1088 | self.log.info('deleted', device_id=self.device_id) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 1089 | |
| 1090 | def start_kpi_collection(self, device_id): |
| 1091 | |
| 1092 | def _collect(device_id, prefix): |
| 1093 | |
| 1094 | try: |
| 1095 | # Step 1: gather metrics from device |
| 1096 | port_metrics = \ |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 1097 | self.pm_metrics.collect_port_metrics(self.get_channel()) |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 1098 | |
| 1099 | # Step 2: prepare the KpiEvent for submission |
| 1100 | # we can time-stamp them here (or could use time derived from OLT |
| 1101 | ts = arrow.utcnow().timestamp |
| 1102 | kpi_event = KpiEvent( |
| 1103 | type=KpiEventType.slice, |
| 1104 | ts=ts, |
| 1105 | prefixes={ |
| 1106 | # OLT NNI port |
| 1107 | prefix + '.nni': MetricValuePairs( |
| 1108 | metrics=port_metrics['nni']), |
| 1109 | # OLT PON port |
| 1110 | prefix + '.pon': MetricValuePairs( |
| 1111 | metrics=port_metrics['pon']) |
| 1112 | } |
| 1113 | ) |
| 1114 | |
| 1115 | # Step 3: submit |
| 1116 | self.adapter_agent.submit_kpis(kpi_event) |
| 1117 | |
| 1118 | except Exception as e: |
| 1119 | log.exception('failed-to-submit-kpis', e=e) |
Stephane Barbarie | 5253c65 | 2017-03-22 16:29:46 -0400 | [diff] [blame] | 1120 | |
Sergio Slobodrian | 98eff41 | 2017-03-15 14:46:30 -0400 | [diff] [blame] | 1121 | self.pm_metrics.start_collector(_collect) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1122 | |
Stephane Barbarie | 3559506 | 2018-02-08 08:34:39 -0500 | [diff] [blame] | 1123 | def stop_kpi_collection(self): |
| 1124 | self.pm_metrics.stop_collector() |
| 1125 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1126 | def get_interface_config(self, data): |
| 1127 | interfaceConfig = InterfaceConfig() |
| 1128 | if isinstance(data, ChannelgroupConfig): |
| 1129 | interfaceConfig.channel_group_config.CopyFrom(data) |
| 1130 | elif isinstance(data, ChannelpartitionConfig): |
| 1131 | interfaceConfig.channel_partition_config.CopyFrom(data) |
| 1132 | elif isinstance(data, ChannelpairConfig): |
| 1133 | interfaceConfig.channel_pair_config.CopyFrom(data) |
| 1134 | elif isinstance(data, ChannelterminationConfig): |
| 1135 | interfaceConfig.channel_termination_config.CopyFrom(data) |
| 1136 | elif isinstance(data, OntaniConfig): |
| 1137 | interfaceConfig.ont_ani_config.CopyFrom(data) |
| 1138 | elif isinstance(data, VOntaniConfig): |
| 1139 | interfaceConfig.vont_ani_config.CopyFrom(data) |
| 1140 | elif isinstance(data, VEnetConfig): |
| 1141 | interfaceConfig.venet_config.CopyFrom(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1142 | elif isinstance(data, TrafficDescriptorProfileData): |
| 1143 | interfaceConfig.traffic_descriptor_profile_config_data.CopyFrom( |
| 1144 | data) |
| 1145 | elif isinstance(data, TcontsConfigData): |
| 1146 | interfaceConfig.tconts_config_data.CopyFrom(data) |
| 1147 | elif isinstance(data, GemportsConfigData): |
| 1148 | interfaceConfig.gemports_config_data.CopyFrom(data) |
| 1149 | elif isinstance(data, MulticastGemportsConfigData): |
| 1150 | interfaceConfig.multicast_gemports_config_data.CopyFrom(data) |
| 1151 | elif isinstance(data, MulticastDistributionSetData): |
| 1152 | interfaceConfig.multicast_distribution_set_data.CopyFrom(data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1153 | else: |
| 1154 | return None |
| 1155 | return interfaceConfig |
| 1156 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1157 | def xpon_ponsim_olt_interface(self, method_name, data, data2=None): |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1158 | interfaceConfig = self.get_interface_config(data) |
| 1159 | if interfaceConfig is not None: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1160 | self.log.info( |
| 1161 | 'forwarding-{}-request-to-olt-for-interface-type' |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1162 | .format(self.xpon_ponsim_olt_itfs[method_name]['log']), |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1163 | interface_type=type(data)) |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 1164 | stub = ponsim_pb2_grpc.XPonSimStub(self.get_channel()) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1165 | _method = getattr( |
| 1166 | stub, self.xpon_ponsim_olt_itfs[method_name]['method_name']) |
| 1167 | if isinstance(data, TcontsConfigData): |
| 1168 | tcont_config = TcontInterfaceConfig() |
| 1169 | tcont_config.tconts_config_data.CopyFrom(data) |
| 1170 | tcont_config.traffic_descriptor_profile_config_data.CopyFrom( |
| 1171 | data2) |
| 1172 | _method(tcont_config) |
| 1173 | else: |
| 1174 | _method(interfaceConfig) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1175 | self.log.info('success') |
| 1176 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1177 | def create_interface(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1178 | _method_name = sys._getframe().f_code.co_name |
| 1179 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1180 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1181 | def update_interface(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1182 | _method_name = sys._getframe().f_code.co_name |
| 1183 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1184 | |
| 1185 | def remove_interface(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1186 | _method_name = sys._getframe().f_code.co_name |
| 1187 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1188 | |
| 1189 | def create_tcont(self, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1190 | _method_name = sys._getframe().f_code.co_name |
| 1191 | self.xpon_ponsim_olt_interface(_method_name, tcont_data, |
| 1192 | traffic_descriptor_data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1193 | |
| 1194 | def update_tcont(self, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1195 | _method_name = sys._getframe().f_code.co_name |
| 1196 | self.xpon_ponsim_olt_interface(_method_name, tcont_data, |
| 1197 | traffic_descriptor_data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1198 | |
| 1199 | def remove_tcont(self, tcont_data, traffic_descriptor_data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1200 | _method_name = sys._getframe().f_code.co_name |
| 1201 | self.xpon_ponsim_olt_interface(_method_name, tcont_data, |
| 1202 | traffic_descriptor_data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1203 | |
| 1204 | def create_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1205 | _method_name = sys._getframe().f_code.co_name |
| 1206 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1207 | |
| 1208 | def update_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1209 | _method_name = sys._getframe().f_code.co_name |
| 1210 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1211 | |
| 1212 | def remove_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1213 | _method_name = sys._getframe().f_code.co_name |
| 1214 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1215 | |
| 1216 | def create_multicast_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1217 | _method_name = sys._getframe().f_code.co_name |
| 1218 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1219 | |
| 1220 | def update_multicast_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1221 | _method_name = sys._getframe().f_code.co_name |
| 1222 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1223 | |
| 1224 | def remove_multicast_gemport(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1225 | _method_name = sys._getframe().f_code.co_name |
| 1226 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1227 | |
| 1228 | def create_multicast_distribution_set(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1229 | _method_name = sys._getframe().f_code.co_name |
| 1230 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1231 | |
| 1232 | def update_multicast_distribution_set(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1233 | _method_name = sys._getframe().f_code.co_name |
| 1234 | self.xpon_ponsim_olt_interface(_method_name, data); |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1235 | |
| 1236 | def remove_multicast_distribution_set(self, data): |
khenaidoo | f3593a8 | 2018-06-01 16:41:31 -0400 | [diff] [blame] | 1237 | _method_name = sys._getframe().f_code.co_name |
| 1238 | self.xpon_ponsim_olt_interface(_method_name, data); |
Scott Baker | 50873cc | 2018-09-21 18:14:09 -0700 | [diff] [blame] | 1239 | |
| 1240 | def simulate_alarm(self, alarm): |
| 1241 | # Ponsim_olt implements its own AdapterAlarms class, rather than using the Voltha alarm extension. Until that |
| 1242 | # has been reconciled, temporarily instantiate the Voltha alarm extension's AdapterAlarms here, for the |
| 1243 | # purpose of sending simulated alarms. |
| 1244 | alarms = VolthaAdapterAlarms(self.adapter_agent, self.device_id, self.logical_device_id) |
| 1245 | simulator = AdapterAlarmSimulator(alarms) |
| 1246 | simulator.simulate_alarm(alarm) |