blob: 111e0fc8877de3c32d3fd521bcb2b81f10c0177f [file] [log] [blame]
Dinesh Belwalkard1cbf4c2018-12-13 13:34:05 -08001#
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"""
18Openolt adapter.
19"""
20import arrow
21import grpc
22import structlog
23from google.protobuf.empty_pb2 import Empty
24from google.protobuf.json_format import MessageToDict
25from scapy.layers.inet import Raw
26import json
27from google.protobuf.message import Message
28from grpc._channel import _Rendezvous
29from scapy.layers.l2 import Ether, Dot1Q
30from simplejson import dumps
31from twisted.internet import reactor
32from twisted.internet.defer import inlineCallbacks, returnValue
33from twisted.internet.task import LoopingCall
34
35from python.adapters.common.frameio.frameio import BpfProgramFilter, hexify
36from python.common.utils.asleep import asleep
37from python.common.utils.registry import registry
38from python.adapters.iadapter import OltAdapter
39from python.adapters.kafka.kafka_proxy import get_kafka_proxy
40from python.protos import openolt_pb2
41from python.protos import third_party
42from python.protos.common_pb2 import OperStatus, ConnectStatus
43from python.protos.common_pb2 import LogLevel
44from python.protos.common_pb2 import OperationResp
45from python.protos.inter_container_pb2 import SwitchCapability, PortCapability, \
46 InterAdapterMessageType, InterAdapterResponseBody
47from python.protos.device_pb2 import Port, PmConfig, PmConfigs. \
48 DeviceType, DeviceTypes
49from python.protos.adapter_pb2 import Adapter
50from python.protos.adapter_pb2 import AdapterConfig
51
52
53from python.protos.events_pb2 import KpiEvent, KpiEventType, MetricValuePairs
54from python.protos.logical_device_pb2 import LogicalPort
55from 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
59from python.protos.openflow_13_pb2 import ofp_port
60from python.protos.ponsim_pb2 import FlowTable, PonSimFrame, PonSimMetricsRequest
61
62_ = third_party
63log = 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
76class 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