Exemple #1
0
 def send_proxied_message(self, proxy_address, msg):
     self.log.info('sending-proxied-message')
     if isinstance(msg, FlowTable):
         stub = ponsim_pb2.PonSimStub(self.get_channel())
         self.log.info('pushing-onu-flow-table', port=msg.port)
         res = stub.UpdateFlowTable(msg)
         self.core_proxy.receive_proxied_message(proxy_address, res)
Exemple #2
0
    def update_flow_table(self, flows):
        yield self.get_channel()
        stub = ponsim_pb2.PonSimStub(self.channel)

        self.log.info('pushing-olt-flow-table')
        stub.UpdateFlowTable(FlowTable(port=0, flows=flows))
        self.log.info('success')
Exemple #3
0
 def collect_port_metrics(self, channel):
     rtrn_port_metrics = dict()
     stub = ponsim_pb2.PonSimStub(channel)
     stats = stub.GetStats(Empty())
     rtrn_port_metrics['pon'] = self.extract_pon_metrics(stats)
     rtrn_port_metrics['nni'] = self.extract_nni_metrics(stats)
     return rtrn_port_metrics
Exemple #4
0
 def process_inter_adapter_message(self, request):
     self.log.info('process-inter-adapter-message', msg=request)
     try:
         if request.header.type == InterAdapterMessageType.FLOW_REQUEST:
             f = FlowTable()
             if request.body:
                 request.body.Unpack(f)
                 stub = ponsim_pb2.PonSimStub(self.channel)
                 self.log.info('pushing-onu-flow-table')
                 res = stub.UpdateFlowTable(f)
                 # Send response back
                 reply = InterAdapterResponseBody()
                 reply.status = True
                 self.log.info('sending-response-back', reply=reply)
                 yield self.adapter_proxy.send_inter_adapter_message(
                     msg=reply,
                     type=InterAdapterMessageType.FLOW_RESPONSE,
                     from_adapter=self.adapter.name,
                     to_adapter=request.header.from_topic,
                     to_device_id=request.header.to_device_id,
                     message_id=request.header.id)
         elif request.header.type == InterAdapterMessageType.METRICS_REQUEST:
             m = PonSimMetricsRequest()
             if request.body:
                 request.body.Unpack(m)
                 stub = ponsim_pb2.PonSimStub(self.channel)
                 self.log.info('proxying onu stats request', port=m.port)
                 res = stub.GetStats(m)
                 # Send response back
                 reply = InterAdapterResponseBody()
                 reply.status = True
                 reply.body.Pack(res)
                 self.log.info('sending-response-back', reply=reply)
                 yield self.adapter_proxy.send_inter_adapter_message(
                     msg=reply,
                     type=InterAdapterMessageType.METRICS_RESPONSE,
                     from_adapter=self.adapter.name,
                     to_adapter=request.header.from_topic,
                     to_device_id=request.header.to_device_id,
                     message_id=request.header.id)
     except Exception as e:
         self.log.exception("error-processing-inter-adapter-message", e=e)
Exemple #5
0
    def packet_out(self, egress_port, msg):
        self.log.info('sending-packet-out',
                      egress_port=egress_port,
                      msg=hexify(msg))
        pkt = Ether(msg)
        out_pkt = pkt
        if egress_port != self.nni_port.port_no:
            # don't do the vlan manipulation for the NNI port, vlans are already correct
            out_pkt = (Ether(src=pkt.src, dst=pkt.dst) /
                       Dot1Q(vlan=egress_port, type=pkt.type) / pkt.payload)

        # TODO need better way of mapping logical ports to PON ports
        out_port = self.nni_port.port_no if egress_port == self.nni_port.port_no else 1

        # send over grpc stream
        stub = ponsim_pb2.PonSimStub(self.channel)
        frame = PonSimFrame(id=self.device_id,
                            payload=str(out_pkt),
                            out_port=out_port)
        stub.SendFrame(frame)
Exemple #6
0
    def rcv_grpc(self):
        """
        This call establishes a GRPC stream to receive frames.
        """
        yield self.get_channel()
        stub = ponsim_pb2.PonSimStub(self.channel)
        # stub = ponsim_pb2.PonSimStub(self.get_channel())

        # Attempt to establish a grpc stream with the remote ponsim service
        self.frames = stub.ReceiveFrames(Empty())

        self.log.info('start-receiving-grpc-frames')

        try:
            for frame in self.frames:
                self.log.info('received-grpc-frame',
                              frame_len=len(frame.payload))
                yield self._rcv_frame(frame.payload)

        except _Rendezvous, e:
            log.warn('grpc-connection-lost', message=e.message)
Exemple #7
0
    def reenable(self):
        self.log.info('re-enabling', device_id=self.device_id)

        # Set the ofp_port_no and nni_port in case we bypassed the reconcile
        # process if the device was in DISABLED state on voltha restart
        if not self.ofp_port_no and not self.nni_port:
            yield self.get_channel()
            stub = ponsim_pb2.PonSimStub(self.channel)
            info = stub.GetDeviceInfo(Empty())
            log.info('got-info', info=info)
            self.ofp_port_no = info.nni_port
            ports = yield self._get_nni_port()
            # For ponsim, we are using only 1 NNI port
            if ports.items:
                self.nni_port = ports.items[0]

        # Update the state of the NNI port
        yield self.core_proxy.port_state_update(self.device_id,
                                                port_type=Port.ETHERNET_NNI,
                                                port_no=self.ofp_port_no,
                                                oper_status=OperStatus.ACTIVE)

        # Update the state of the PON port
        yield self.core_proxy.port_state_update(self.device_id,
                                                port_type=Port.PON_OLT,
                                                port_no=1,
                                                oper_status=OperStatus.ACTIVE)

        # Set the operational state of the device to ACTIVE and connect status to REACHABLE
        yield self.core_proxy.device_state_update(
            self.device_id,
            connect_status=ConnectStatus.REACHABLE,
            oper_status=OperStatus.ACTIVE)

        # TODO: establish frame grpc-stream
        # yield reactor.callInThread(self.rcv_grpc)

        self.start_kpi_collection(self.device_id)

        self.log.info('re-enabled', device_id=self.device_id)
Exemple #8
0
    def activate(self, device):
        try:
            self.log.info('activating')

            if not device.host_and_port:
                device.oper_status = OperStatus.FAILED
                device.reason = 'No host_and_port field provided'
                self.core_proxy.device_update(device)
                return

            yield self.get_channel()
            stub = ponsim_pb2.PonSimStub(self.channel)
            info = stub.GetDeviceInfo(Empty())
            log.info('got-info', info=info, device_id=device.id)
            self.ofp_port_no = info.nni_port

            device.root = True
            device.vendor = 'ponsim'
            device.model = 'n/a'
            device.serial_number = device.host_and_port
            device.mac_address = "AA:BB:CC:DD:EE:FF"
            yield self.core_proxy.device_update(device)

            # Now set the initial PM configuration for this device
            self.pm_metrics = AdapterPmMetrics(device)
            pm_config = self.pm_metrics.make_proto()
            log.info("initial-pm-config", pm_config=pm_config)
            self.core_proxy.device_pm_config_update(pm_config, init=True)

            # Setup alarm handler
            self.alarms = AdapterAlarms(self.adapter, device)

            nni_port = Port(port_no=info.nni_port,
                            label='NNI facing Ethernet port',
                            type=Port.ETHERNET_NNI,
                            oper_status=OperStatus.ACTIVE)
            self.nni_port = nni_port
            yield self.core_proxy.port_created(device.id, nni_port)
            yield self.core_proxy.port_created(
                device.id,
                Port(port_no=1,
                     label='PON port',
                     type=Port.PON_OLT,
                     oper_status=OperStatus.ACTIVE))

            yield self.core_proxy.device_state_update(
                device.id,
                connect_status=ConnectStatus.REACHABLE,
                oper_status=OperStatus.ACTIVE)

            # register ONUS
            self.log.info('onu-found', onus=info.onus, len=len(info.onus))
            for onu in info.onus:
                vlan_id = onu.uni_port
                yield self.core_proxy.child_device_detected(
                    parent_device_id=device.id,
                    parent_port_no=1,
                    child_device_type='ponsim_onu',
                    channel_id=vlan_id,
                )

            self.log.info('starting-frame-grpc-stream')
            reactor.callInThread(self.rcv_grpc)
            self.log.info('started-frame-grpc-stream')

            # Start collecting stats from the device after a brief pause
            self.start_kpi_collection(device.id)
        except Exception as e:
            log.exception("Exception-activating", e=e)