Dinesh Belwalkar | d1cbf4c | 2018-12-13 13:34:05 -0800 | [diff] [blame^] | 1 | # |
| 2 | # Copyright 2018 the original author or authors. |
| 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 | Openolt adapter. |
| 19 | """ |
| 20 | import arrow |
| 21 | import grpc |
| 22 | import structlog |
| 23 | from google.protobuf.empty_pb2 import Empty |
| 24 | from google.protobuf.json_format import MessageToDict |
| 25 | from scapy.layers.inet import Raw |
| 26 | import json |
| 27 | from google.protobuf.message import Message |
| 28 | from grpc._channel import _Rendezvous |
| 29 | from scapy.layers.l2 import Ether, Dot1Q |
| 30 | from simplejson import dumps |
| 31 | from twisted.internet import reactor |
| 32 | from twisted.internet.defer import inlineCallbacks, returnValue |
| 33 | from twisted.internet.task import LoopingCall |
| 34 | |
| 35 | from python.adapters.common.frameio.frameio import BpfProgramFilter, hexify |
| 36 | from python.common.utils.asleep import asleep |
| 37 | from python.common.utils.registry import registry |
| 38 | from python.adapters.iadapter import OltAdapter |
| 39 | from python.adapters.kafka.kafka_proxy import get_kafka_proxy |
| 40 | from python.protos import openolt_pb2 |
| 41 | from python.protos import third_party |
| 42 | from python.protos.common_pb2 import OperStatus, ConnectStatus |
| 43 | from python.protos.common_pb2 import LogLevel |
| 44 | from python.protos.common_pb2 import OperationResp |
| 45 | from python.protos.inter_container_pb2 import SwitchCapability, PortCapability, \ |
| 46 | InterAdapterMessageType, InterAdapterResponseBody |
| 47 | from python.protos.device_pb2 import Port, PmConfig, PmConfigs. \ |
| 48 | DeviceType, DeviceTypes |
| 49 | from python.protos.adapter_pb2 import Adapter |
| 50 | from python.protos.adapter_pb2 import AdapterConfig |
| 51 | |
| 52 | |
| 53 | from python.protos.events_pb2 import KpiEvent, KpiEventType, MetricValuePairs |
| 54 | from python.protos.logical_device_pb2 import LogicalPort |
| 55 | from python.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \ |
| 56 | OFPPF_1GB_FD, \ |
| 57 | OFPC_GROUP_STATS, OFPC_PORT_STATS, OFPC_TABLE_STATS, OFPC_FLOW_STATS, \ |
| 58 | ofp_switch_features, ofp_desc |
| 59 | from python.protos.openflow_13_pb2 import ofp_port |
| 60 | from python.protos.ponsim_pb2 import FlowTable, PonSimFrame, PonSimMetricsRequest |
| 61 | |
| 62 | _ = third_party |
| 63 | log = structlog.get_logger() |
| 64 | #OpenOltDefaults = { |
| 65 | # 'support_classes': { |
| 66 | # 'platform': OpenOltPlatform, |
| 67 | # 'resource_mgr': OpenOltResourceMgr, |
| 68 | # 'flow_mgr': OpenOltFlowMgr, |
| 69 | # 'alarm_mgr': OpenOltAlarmMgr, |
| 70 | # 'stats_mgr': OpenOltStatisticsMgr, |
| 71 | # 'bw_mgr': OpenOltBW |
| 72 | # } |
| 73 | #} |
| 74 | |
| 75 | |
| 76 | class OpenoltAdapter(object): |
| 77 | name = 'openolt' |
| 78 | |
| 79 | supported_device_types = [ |
| 80 | DeviceType( |
| 81 | id=name, |
| 82 | adapter=name, |
| 83 | accepts_bulk_flow_update=True, |
| 84 | accepts_direct_logical_flows_update=True |
| 85 | ) |
| 86 | ] |
| 87 | |
| 88 | def __init__(self, core_proxy, adapter_proxy, config): |
| 89 | self.adapter_agent = adapter_agent |
| 90 | self.config = config |
| 91 | self.descriptor = Adapter( |
| 92 | id=self.name, |
| 93 | vendor='OLT white box vendor', |
| 94 | version='0.1', |
| 95 | config=config |
| 96 | ) |
| 97 | log.debug('openolt.__init__', adapter_agent=adapter_agent) |
| 98 | self.devices = dict() # device_id -> OpenoltDevice() |
| 99 | self.interface = registry('main').get_args().interface |
| 100 | self.logical_device_id_to_root_device_id = dict() |
| 101 | self.num_devices = 0 |
| 102 | |