Пример #1
0
Файл: bess.py Проект: vivi/bess
    def run_module_command(self, name, cmd, arg_type, arg):
        request = bess_msg.CommandRequest()
        request.name = name
        request.cmd = cmd

        try:
            message_type = getattr(module_msg, arg_type)
        except AttributeError as e:
            raise self.APIError('Unknown arg "%s"' % arg_type)

        try:
            arg_msg = pb_conv.dict_to_protobuf(message_type, arg)
        except (KeyError, ValueError) as e:
            raise self.APIError(e)

        request.arg.Pack(arg_msg)

        try:
            response = self._request('ModuleCommand', request)
        except self.Error as e:
            e.info.update(module=name, command=cmd, command_arg=arg)
            raise

        if response.HasField('data'):
            response_type_str = response.data.type_url.split('.')[-1]
            response_type = getattr(module_msg, response_type_str,
                                    bess_msg.EmptyArg)
            result = response_type()
            response.data.Unpack(result)
            return result
        else:
            return response
Пример #2
0
    def addFAR(self, far, debug=False):
        # set action value for far action
        action = self._setActionValue(far)

        # parse fields of far into ExactMatchCommandAddArg
        f = module_msg.ExactMatchCommandAddArg(
            gate=far.tunnelType,
            fields=[
                util_msg.FieldData(value_int=far.farID),
                util_msg.FieldData(value_int=far.fseID),
            ],
            values=[
                util_msg.FieldData(value_int=action),
                util_msg.FieldData(value_int=far.tunnelType),
                util_msg.FieldData(value_int=far.tunnelIP4Src),
                util_msg.FieldData(value_int=far.tunnelIP4Dst),
                util_msg.FieldData(value_int=far.tunnelTEID),
                util_msg.FieldData(value_int=far.tunnelPort),
            ],
        )

        # store into Any() message protobuf type
        any = Any()
        any.Pack(f)

        # send request to UPF to add rule
        response = self.bess_client.ModuleCommand(
            bess_msg.CommandRequest(name="farLookup", cmd="add", arg=any),
            timeout=5,
        )
        if debug:
            print(response)

        self.fars.append(far)
Пример #3
0
    def _readFlowMeasurement(self, module, clear, quantiles):
        # create request for flow measurements and send to bess
        request = module_msg.FlowMeasureCommandReadArg(
            clear=clear,
            latency_percentiles=quantiles,
            jitter_percentiles=quantiles,
        )
        any = Any()
        any.Pack(request)

        response = self.bess_client.ModuleCommand(
            bess_msg.CommandRequest(
                name=module,
                cmd="read",
                arg=any,
            ),
            timeout=5,
        )

        # unpack response and return results
        data = response.data
        msg = module_msg.FlowMeasureReadResponse()
        if data.Is(module_msg.FlowMeasureReadResponse.DESCRIPTOR):
            data.Unpack(msg)

        msg = MessageToDict(msg)
        if "statistics" in msg:
            return msg["statistics"]

        return msg
Пример #4
0
    def addPDR(self, pdr, debug=False):
        for qerID in pdr.qerIDList:
            qerID = qerID
            break

        # parse params of PDR tuple into a wildcard match message to send to BESS
        f = module_msg.WildcardMatchCommandAddArg(
            gate=pdr.needDecap,
            priority=4294967295 -
            pdr.precedence,  # XXX: golang max 32 bit uint
            values=[
                util_msg.FieldData(value_int=pdr.srcIface),
                util_msg.FieldData(value_int=pdr.tunnelIP4Dst),
                util_msg.FieldData(value_int=pdr.tunnelTEID),
                util_msg.FieldData(value_int=pdr.srcIP),
                util_msg.FieldData(value_int=pdr.dstIP),
                util_msg.FieldData(value_int=pdr.srcPort),
                util_msg.FieldData(value_int=pdr.dstPort),
                util_msg.FieldData(value_int=pdr.proto),
            ],
            masks=[
                util_msg.FieldData(value_int=pdr.srcIfaceMask),
                util_msg.FieldData(value_int=pdr.tunnelIP4DstMask),
                util_msg.FieldData(value_int=pdr.tunnelTEIDMask),
                util_msg.FieldData(value_int=pdr.srcIPMask),
                util_msg.FieldData(value_int=pdr.dstIPMask),
                util_msg.FieldData(value_int=pdr.srcPortMask),
                util_msg.FieldData(value_int=pdr.dstPortMask),
                util_msg.FieldData(value_int=pdr.protoMask),
            ],
            valuesv=[
                util_msg.FieldData(value_int=pdr.pdrID),
                util_msg.FieldData(value_int=pdr.fseID),
                util_msg.FieldData(value_int=pdr.ctrID),
                util_msg.FieldData(value_int=qerID),
                util_msg.FieldData(value_int=pdr.farID),
            ],
        )

        # store into Any() message protobuf type
        any = Any()
        any.Pack(f)

        # send request to UPF to add rule
        response = self.bess_client.ModuleCommand(
            bess_msg.CommandRequest(name="pdrLookup", cmd="add", arg=any),
            timeout=5,
        )
        if debug:
            print(response)

        self.pdrs.append(pdr)
Пример #5
0
    def addApplicationQER(self, qer, debug=False):
        ''' installs uplink and downlink applicaiton QER '''
        rates = self._calcRates(
            qer.ulGbr,
            qer.ulMbr,
            qer.dlGbr,
            qer.dlMbr,
            qer.burstDurationMs,
        )

        # construct UL/DL QosCommandAddArg's and send to BESS
        for srcIface in [ACCESS, CORE]:
            f = module_msg.QosCommandAddArg(
                gate=qer.gate,
                cir=int(rates.ulCir)
                if srcIface == ACCESS else int(rates.dlCir),
                pir=int(rates.ulPir)
                if srcIface == ACCESS else int(rates.dlPir),
                cbs=int(rates.ulCbs)
                if srcIface == ACCESS else int(rates.dlCbs),
                pbs=int(rates.ulPbs)
                if srcIface == ACCESS else int(rates.dlPbs),
                ebs=int(rates.ulEbs)
                if srcIface == ACCESS else int(rates.dlEbs),
                fields=[
                    util_msg.FieldData(value_int=srcIface),
                    util_msg.FieldData(value_int=qer.qerID),
                    util_msg.FieldData(value_int=qer.fseID)
                ],
                values=[util_msg.FieldData(value_int=qer.qfi)],
            )

            any = Any()
            any.Pack(f)

            response = self.bess_client.ModuleCommand(
                bess_msg.CommandRequest(name="appQERLookup",
                                        cmd="add",
                                        arg=any),
                timeout=5,
            )
            if debug:
                print(response)

        self.appQers.append(qer)
Пример #6
0
    def delSessionQER(self, qer, debug=False):
        ''' deletes uplink and downlink session QER '''
        for srcIface in [ACCESS, CORE]:
            f = module_msg.QosCommandDeleteArg(fields=[
                util_msg.FieldData(value_int=srcIface),
                util_msg.FieldData(value_int=qer.fseID),
            ], )
            any = Any()
            any.Pack(f)

            response = self.bess_client.ModuleCommand(
                bess_msg.CommandRequest(name="sessionQERLookup",
                                        cmd="delete",
                                        arg=any),
                timeout=5,
            )
            if debug:
                print(response)
Пример #7
0
    def delFAR(self, far, debug=False):
        # parse params of far into ExactMatchCommandDeleteArg
        f = module_msg.ExactMatchCommandDeleteArg(fields=[
            util_msg.FieldData(value_int=far.farID),
            util_msg.FieldData(value_int=far.fseID),
        ], )

        # store into Any() message protobuf type
        any = Any()
        any.Pack(f)

        # send request to UPF to delete rule
        response = self.bess_client.ModuleCommand(
            bess_msg.CommandRequest(name="farLookup", cmd="delete", arg=any),
            timeout=5,
        )
        if debug:
            print(response)
Пример #8
0
    def delPDR(self, pdr, debug=False):
        # parse params of pdr into WildcardMatchCommandDeleteArg
        f = module_msg.WildcardMatchCommandDeleteArg(
            values=[
                util_msg.FieldData(value_int=pdr.srcIface),
                util_msg.FieldData(value_int=pdr.tunnelIP4Dst),
                util_msg.FieldData(value_int=pdr.tunnelTEID),
                util_msg.FieldData(value_int=pdr.srcIP),
                util_msg.FieldData(value_int=pdr.dstIP),
                util_msg.FieldData(value_int=pdr.srcPort),
                util_msg.FieldData(value_int=pdr.dstPort),
                util_msg.FieldData(value_int=pdr.proto),
            ],
            masks=[
                util_msg.FieldData(value_int=pdr.srcIfaceMask),
                util_msg.FieldData(value_int=pdr.tunnelIP4DstMask),
                util_msg.FieldData(value_int=pdr.tunnelTEIDMask),
                util_msg.FieldData(value_int=pdr.srcIPMask),
                util_msg.FieldData(value_int=pdr.dstIPMask),
                util_msg.FieldData(value_int=pdr.srcPortMask),
                util_msg.FieldData(value_int=pdr.dstPortMask),
                util_msg.FieldData(value_int=pdr.protoMask),
            ],
        )

        # store into Any() message protobuf type
        any = Any()
        any.Pack(f)

        # send request to UPF to delete rule
        response = self.bess_client.ModuleCommand(
            bess_msg.CommandRequest(name="pdrLookup", cmd="delete", arg=any),
            timeout=5,
        )
        if debug:
            print(response)