Exemplo n.º 1
0
    def port_state_update(self,
                          device_id,
                          port_type,
                          port_no,
                          oper_status):
        id = ID()
        id.id = device_id
        pt = IntType()
        pt.val = port_type
        pNo = IntType()
        pNo.val = port_no
        o_status = IntType()
        o_status.val = oper_status

        to_topic = self.get_core_topic(device_id)
        reply_topic = self.get_adapter_topic()

        # to_topic = createSubTopic(self.core_topic, device_id)
        # reply_topic = createSubTopic(self.listening_topic, device_id)
        res = yield self.invoke(rpc="PortStateUpdate",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                device_id=id,
                                port_type=pt,
                                port_no=pNo,
                                oper_status=o_status)
        returnValue(res)
Exemplo n.º 2
0
    def child_devices_state_update(self, parent_device_id,
                                   oper_status=None,
                                   connect_status=None):

        id = ID()
        id.id = parent_device_id
        o_status = IntType()
        if oper_status or oper_status == OperStatus.UNKNOWN:
            o_status.val = oper_status
        else:
            o_status.val = -1
        c_status = IntType()
        if connect_status or connect_status == ConnectStatus.UNKNOWN:
            c_status.val = connect_status
        else:
            c_status.val = -1

        to_topic = self.get_core_topic(parent_device_id)
        reply_topic = self.get_adapter_topic()

        # to_topic = createSubTopic(self.core_topic, parent_device_id)
        # reply_topic = createSubTopic(self.listening_topic, parent_device_id)
        res = yield self.invoke(rpc="child_devices_state_update",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                parent_device_id=id,
                                oper_status=o_status,
                                connect_status=c_status)
        returnValue(res)
Exemplo n.º 3
0
    def children_state_update(self,
                              device_id,
                              oper_status=None,
                              connect_status=None):
        dev_id = ID()
        dev_id.id = device_id
        o_status = IntType()
        if oper_status or oper_status == OperStatus.UNKNOWN:
            o_status.val = oper_status
        else:
            o_status.val = -1
        c_status = IntType()
        if connect_status or connect_status == ConnectStatus.UNKNOWN:
            c_status.val = connect_status
        else:
            c_status.val = -1

        to_topic = self.get_core_topic(device_id)
        reply_topic = self.get_adapter_topic()

        res = yield self.invoke(rpc="ChildrenStateUpdate",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                device_id=dev_id,
                                oper_status=o_status,
                                connect_status=c_status)
        returnValue(res)
Exemplo n.º 4
0
    def get_ports(self, device_id, port_type):
        dev_id = ID()
        dev_id.id = device_id
        p_type = IntType()
        p_type.val = port_type
        to_topic = self.get_core_topic(device_id)
        reply_topic = self.get_adapter_topic()

        res = yield self.invoke(rpc="GetPorts",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                device_id=dev_id,
                                port_type=p_type)
        returnValue(res)
Exemplo n.º 5
0
    def get_ports(self, device_id, port_type):
        id = ID()
        id.id = device_id
        p_type = IntType()
        p_type.val = port_type
        to_topic = self.get_core_topic(device_id)
        reply_topic = self.get_adapter_topic()

        # to_topic = createSubTopic(self.core_topic, device_id)
        # reply_topic = createSubTopic(self.listening_topic, device_id)
        res = yield self.invoke(rpc="GetPorts",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                device_id=id,
                                port_type=p_type)
        returnValue(res)
Exemplo n.º 6
0
    def receive_packet_out(self, deviceId, outPort, packet, **kwargs):
        try:
            d_id = StrType()
            if deviceId:
                deviceId.Unpack(d_id)
            else:
                return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                    reason="deviceid-invalid")

            op = IntType()
            if outPort:
                outPort.Unpack(op)
            else:
                return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                    reason="outport-invalid")

            p = ofp_packet_out()
            if packet:
                packet.Unpack(p)
            else:
                return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                    reason="packet-invalid")

            return (True, self.adapter.receive_packet_out(d_id.val, op.val, p))
        except Exception as e:
            log.exception("error-processing-receive_packet_out", e=e)
Exemplo n.º 7
0
    def receive_packet_out(self, deviceId, outPort, packet, **_kwargs):  # pylint: disable=invalid-name
        try:
            d_id = StrType()
            if deviceId:
                deviceId.Unpack(d_id)
            else:
                return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                    reason="device-id-invalid")
            port_number = IntType()
            if outPort:
                outPort.Unpack(port_number)
            else:
                return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                    reason="outport-invalid")

            pkt = ofp_packet_out()
            if packet:
                packet.Unpack(pkt)
            else:
                return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                    reason="packet-invalid")

            return True, self.adapter.receive_packet_out(
                d_id.val, port_number.val, pkt)

        except Exception as e:
            log.exception("error-processing-receive_packet_out", e=e)
            return False, Error(
                code=ErrorCode.INVALID_PARAMETERS,
                reason="exception-during-processing: {}".format(str(e)))
Exemplo n.º 8
0
 def send_packet_in(self, device_id, port, packet, response_required=True):
     log.debug("send_packet_in", device_id=device_id)
     proto_id = ID()
     proto_id.id = device_id
     port_num = IntType()
     port_num.val = port
     pac = Packet()
     pac.payload = packet
     to_topic = self.get_core_topic(device_id)
     reply_topic = self.get_adapter_topic()
     res = yield self.invoke(rpc="PacketIn",
                             to_topic=to_topic,
                             reply_topic=reply_topic,
                             device_id=proto_id,
                             port=port_num,
                             packet=pac,
                             response_required=response_required)
     returnValue(res)
Exemplo n.º 9
0
 def _to_proto(self, **kwargs):
     encoded = {}
     for k, v in kwargs.iteritems():
         if isinstance(v, Message):
             encoded[k] = v
         elif type(v) == int:
             i_proto = IntType()
             i_proto.val = v
             encoded[k] = i_proto
         elif type(v) == str:
             s_proto = StrType()
             s_proto.val = v
             encoded[k] = s_proto
         elif type(v) == bool:
             b_proto = BoolType()
             b_proto.val = v
             encoded[k] = b_proto
     return encoded
Exemplo n.º 10
0
 def send_packet_in(self, device_id, port, packet):
     log.debug("send_packet_in", device_id=device_id)
     proto_id = ID()
     proto_id.id = device_id
     p = IntType()
     p.val = port
     pac = Packet()
     pac.payload = packet
     to_topic = self.get_core_topic(device_id)
     reply_topic = self.get_adapter_topic()
     # to_topic = createSubTopic(self.core_topic, device_id)
     # reply_topic = createSubTopic(self.listening_topic, device_id)
     res = yield self.invoke(rpc="PacketIn",
                             to_topic=to_topic,
                             reply_topic=reply_topic,
                             device_id=proto_id,
                             port=p,
                             packet=pac)
     returnValue(res)
Exemplo n.º 11
0
 def _to_proto(**kwargs):
     encoded = {}
     for k, val in kwargs.items():
         if isinstance(val, Message):
             encoded[k] = val
         elif isinstance(val, int):
             i_proto = IntType()
             i_proto.val = val
             encoded[k] = i_proto
         elif isinstance(val, str):
             s_proto = StrType()
             s_proto.val = val
             encoded[k] = s_proto
         elif isinstance(val, bool):
             b_proto = BoolType()
             b_proto.val = val
             encoded[k] = b_proto
         else:
             raise TypeError('Unsupported type: {} for key {}'.format(
                 type(val), k))
     return encoded
Exemplo n.º 12
0
    def child_device_lost(self, pDeviceId, pPortNo, onuID, **_kwargs):  # pylint: disable=invalid-name
        if not pDeviceId:
            return False, Error(code=ErrorCode.INVALID_PARAMETER,
                                reason="device-id")
        if not pPortNo:
            return False, Error(code=ErrorCode.INVALID_PARAMETER,
                                reason="p-port-no")
        if not onuID:
            return False, Error(code=ErrorCode.INVALID_PARAMETER,
                                reason="onu-id")
        str_arg = StrType()
        pDeviceId.Unpack(str_arg)

        port_no = IntType()
        pPortNo.Unpack(port_no)

        oid = IntType()
        onuID.Unpack(oid)

        return True, self.adapter.child_device_lost(str_arg.val, port_no.val,
                                                    oid.val)
Exemplo n.º 13
0
    def ports_state_update(self,
                          device_id,
                          oper_status):
        log.debug("ports_state_update", device_id=device_id, oper_status=oper_status)
        id = ID()
        id.id = device_id
        o_status = IntType()
        o_status.val = oper_status

        to_topic = self.get_core_topic(device_id)
        reply_topic = self.get_adapter_topic()

        # to_topic = createSubTopic(self.core_topic, device_id)
        # reply_topic = createSubTopic(self.listening_topic, device_id)
        res = yield self.invoke(rpc="PortsStateUpdate",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                device_id=id,
                                oper_status=o_status)
        log.debug("ports_state_update_response", device_id=device_id, oper_status=oper_status, response=res)
        returnValue(res)
Exemplo n.º 14
0
    def ports_state_update(
            self,  # TODO: Golang rw-core hdoes not have filter
            device_id,
            port_type_filter,
            oper_status):
        log.debug("ports_state_update",
                  device_id=device_id,
                  oper_status=oper_status)
        dev_id = ID()
        dev_id.id = device_id
        t_filter = IntType()
        t_filter.val = port_type_filter
        o_status = IntType()
        o_status.val = oper_status

        to_topic = self.get_core_topic(device_id)
        reply_topic = self.get_adapter_topic()

        res = yield self.invoke(rpc="PortsStateUpdate",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                device_id=dev_id,
                                port_type_filter=t_filter,
                                oper_status=o_status)
        log.debug("ports_state_update_response",
                  device_id=device_id,
                  port_type_filter=port_type_filter,
                  oper_status=oper_status,
                  response=res)
        returnValue(res)
Exemplo n.º 15
0
    def child_device_detected(self,
                              parent_device_id,
                              parent_port_no,
                              child_device_type,
                              channel_id,
                              **kw):
        id = ID()
        id.id = parent_device_id
        ppn = IntType()
        ppn.val = parent_port_no
        cdt = StrType()
        cdt.val = child_device_type
        channel = IntType()
        channel.val = channel_id
        to_topic = self.get_core_topic(parent_device_id)
        reply_topic = self.get_adapter_topic()

        # to_topic = createSubTopic(self.core_topic, parent_device_id)
        # reply_topic = createSubTopic(self.listening_topic, parent_device_id)
        args = self._to_proto(**kw)
        res = yield self.invoke(rpc="ChildDeviceDetected",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                parent_device_id=id,
                                parent_port_no=ppn,
                                child_device_type=cdt,
                                channel_id=channel,
                                **args)
        returnValue(res)
Exemplo n.º 16
0
    def get_ofp_port_info(self, device, port_no, **kwargs):
        d = Device()
        if device:
            device.Unpack(d)
        else:
            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                reason="device-invalid")
        p = IntType()
        if port_no:
            port_no.Unpack(p)
        else:
            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
                                reason="port-no-invalid")

        return True, self.adapter.get_ofp_port_info(d, p.val)
Exemplo n.º 17
0
    def port_state_update(self, device_id, port_type, port_no, oper_status):
        dev_id = ID()
        dev_id.id = device_id
        ptype = IntType()
        ptype.val = port_type
        pnumber = IntType()
        pnumber.val = port_no
        o_status = IntType()
        o_status.val = oper_status

        to_topic = self.get_core_topic(device_id)
        reply_topic = self.get_adapter_topic()

        res = yield self.invoke(rpc="PortStateUpdate",
                                to_topic=to_topic,
                                reply_topic=reply_topic,
                                device_id=dev_id,
                                port_type=ptype,
                                port_no=pnumber,
                                oper_status=o_status)
        returnValue(res)