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