Fix ponsim xpon broken by earlier commit.
Change-Id: Ifa7ac2470c2b5c5ae70d0a0ca82b3615095d2629
diff --git a/ponsim/grpc_server.py b/ponsim/grpc_server.py
index 13d0ab9..85f12f6 100644
--- a/ponsim/grpc_server.py
+++ b/ponsim/grpc_server.py
@@ -19,6 +19,11 @@
from concurrent import futures
from voltha.protos import third_party
+from voltha.protos.ponsim_pb2 import add_PonSimServicer_to_server
+from voltha.protos.ponsim_pb2 import add_XPonSimServicer_to_server
+from voltha.adapters.asfvolt16_olt.protos.bal_pb2 import add_BalServicer_to_server
+from ponsim_servicer import FlowUpdateHandler, XPonHandler
+from bal_servicer import BalHandler
_ = third_party
@@ -26,23 +31,23 @@
class GrpcServer(object):
- def __init__(self, port, ponsim, x_pon_sim):
+ def __init__(self, port, ponsim, x_pon_sim, device_type):
self.port = port
self.thread_pool = futures.ThreadPoolExecutor(max_workers=10)
self.server = grpc.server(self.thread_pool)
self.ponsim = ponsim
self.x_pon_sim = x_pon_sim
+ self.device_type = device_type
- '''
- service_list: a list of (add_xyzSimServicer_to_server, xyzServicerClass)
- e.g. [(add_PonSimServicer_to_server, FlowUpdateHandler),
- (add_XPonSimServicer_to_server, XPonHandler)]
- '''
- def start(self, service_list):
- log.debug('starting')
- for add_x_to_server, xServiceClass in service_list:
- x_handler = xServiceClass(self.thread_pool, self.ponsim)
- add_x_to_server(x_handler, self.server)
+ def start(self):
+ if self.device_type == 'ponsim':
+ handler = FlowUpdateHandler(self.thread_pool, self.ponsim)
+ add_PonSimServicer_to_server(handler, self.server)
+ x_pon_handler = XPonHandler(self.thread_pool, self.x_pon_sim)
+ add_XPonSimServicer_to_server(x_pon_handler, self.server)
+ else:
+ handler = BalHandler(self.thread_pool, self.ponsim)
+ add_BalServicer_to_server(handler, self.server)
# read in key and certificate
try:
diff --git a/ponsim/main.py b/ponsim/main.py
index 63b47f6..09f78a5 100755
--- a/ponsim/main.py
+++ b/ponsim/main.py
@@ -29,11 +29,6 @@
from common.structlog_setup import setup_logging
from grpc_server import GrpcServer
from realio import RealIo
-from voltha.protos.ponsim_pb2 import add_PonSimServicer_to_server
-from voltha.protos.ponsim_pb2 import add_XPonSimServicer_to_server
-from voltha.adapters.asfvolt16_olt.protos.bal_pb2 import add_BalServicer_to_server
-import ponsim_servicer
-import bal_servicer
from ponsim import PonSim
from ponsim import XPonSim
@@ -174,6 +169,8 @@
self.ponsim = None
self.x_pon_sim = None
self.grpc_server = None
+ self.grpc_services = None
+ self.device_type = args.device_type
self.alarm_config = dict()
self.alarm_config['simulation'] = self.args.alarm_simulation
@@ -182,19 +179,13 @@
if not args.no_banner:
print_banner(self.log)
- if args.device_type == 'ponsim':
- grpc_services = [(add_PonSimServicer_to_server, ponsim_servicer.FlowUpdateHandler)]
- elif args.device_type == 'bal':
- grpc_services = [(add_BalServicer_to_server, bal_servicer.BalHandler)]
- grpc_services.append((add_XPonSimServicer_to_server, ponsim_servicer.XPonHandler))
-
- self.startup_components(grpc_services)
+ self.startup_components()
def start(self):
self.start_reactor() # will not return except Keyboard interrupt
@inlineCallbacks
- def startup_components(self, grpc_services):
+ def startup_components(self):
try:
self.log.info('starting-internal-components')
@@ -206,8 +197,11 @@
self.x_pon_sim = XPonSim()
- self.grpc_server = GrpcServer(self.args.grpc_port, self.ponsim, self.x_pon_sim)
- yield self.grpc_server.start(grpc_services)
+ self.grpc_server = GrpcServer(self.args.grpc_port,
+ self.ponsim,
+ self.x_pon_sim,
+ self.device_type)
+ yield self.grpc_server.start()
self.log.info('started-internal-services')