Exemplo n.º 1
0
    def delete(self, *args, **kwargs):
        """Delete traffic rule queues.

        Args:
            tenant_id: network name of a tenant

        Example URLs:

            DELETE /api/v1/tenants/52313ecb-9d00-4b7d-b873-b55d3d9ada26/trs/ \
              dl_vlan=100,tp_dst=80

        """

        try:

            if len(args) != 2:
                raise ValueError("Invalid url")

            tenant_id = UUID(args[0])
            tenant = RUNTIME.tenants[tenant_id]

            match = Match(args[1])

            tenant.del_traffic_rule(match)

        except ValueError as ex:
            self.send_error(400, message=ex)
        except KeyError as ex:
            self.send_error(404, message=ex)

        self.set_status(204, None)
Exemplo n.º 2
0
    def post(self, *args, **kwargs):
        """Add traffic rule.

        Args:
            tenant_id: network name of a tenant

        Example URLs:

            POST /api/v1/tenants/52313ecb-9d00-4b7d-b873-b55d3d9ada26/slices
            {
                "version" : 1.0,
                "dscp" : 0x40,
                "label" : "video traffic (high priority)",
                "match" : "dl_vlan=100,tp_dst=80",
            }

        """

        try:

            if len(args) != 1:
                raise ValueError("Invalid url")

            request = tornado.escape.json_decode(self.request.body)

            if "version" not in request:
                raise ValueError("missing version element")

            if "dscp" not in request:
                raise ValueError("missing dscp element")

            if "label" not in request:
                raise ValueError("missing label element")

            if "match" not in request:
                raise ValueError("missing match element")

            tenant_id = UUID(args[0])
            tenant = RUNTIME.tenants[tenant_id]

            dscp = DSCP(request["dscp"])
            match = Match(request["match"])

            if "priority" in request:
                tenant.add_traffic_rule(match, dscp, request["label"],
                                        request["priority"])
            else:
                tenant.add_traffic_rule(match, dscp, request["label"])

            url = "/api/v1/tenants/%s/trs/%s" % (tenant_id, match)
            self.set_header("Location", url)

        except TypeError as ex:
            self.send_error(400, message=ex)
        except ValueError as ex:
            self.send_error(400, message=ex)
        except KeyError as ex:
            self.send_error(404, message=ex)

        self.set_status(201, None)
Exemplo n.º 3
0
    def get(self, *args, **kwargs):
        """List traffic rules .

        Args:
            tenant_id: network name of a tenant
            match: the openflow match rule (e.g. dl_vlan=100,tp_dst=80)

        Example URLs:

            GET /api/v1/tenants/52313ecb-9d00-4b7d-b873-b55d3d9ada26/trs
            GET /api/v1/tenants/52313ecb-9d00-4b7d-b873-b55d3d9ada26/trs/ \
              dl_vlan=100,tp_dst=80
        """

        try:

            if len(args) not in [1, 2]:
                raise ValueError("Invalid url")

            tenant_id = UUID(args[0])
            tenant = RUNTIME.tenants[tenant_id]

            if len(args) == 1:
                self.write_as_json(tenant.traffic_rules.values())
            else:
                match = Match(args[1])
                self.write_as_json(tenant.traffic_rules[match])

        except ValueError as ex:
            self.send_error(400, message=ex)
        except KeyError as ex:
            self.send_error(404, message=ex)
    def __setitem__(self, key, value):
        """Set virtual port configuration."""

        if value and not isinstance(value, VirtualPort):
            raise KeyError("Expected VirtualPort, got %s" % type(key))

        # remove virtual link
        if self.__contains__(key):
            self.__delitem__(key)

        self.__uuids__[key] = None

        from empower.ibnp.ibnpserver import IBNPServer
        ibnp_server = get_module(IBNPServer.__module__)

        rule_uuid = uuid4()

        match = Match(key)
        self.my_virtual_port.network_port.add_match(match, rule_uuid)

        priority = None
        if 'priority' in match.match:
            priority = int(match.match['priority'])
            del match.match['priority']

        # set/update intent
        intent = {
            'version': '1.0',
            'uuid': rule_uuid,
            'ttp_uuid': value.endpoint.uuid,
            'ttp_vport': value.virtual_port_id,
            'stp_uuid': self.my_virtual_port.endpoint.uuid,
            'stp_vport': self.my_virtual_port.virtual_port_id,
            'match': match.match
        }

        # custom priorities start at 250 in Ryu, the priority value is summed
        if priority is not None:
            intent['priority'] = priority

        # add new virtual link
        if key in self.__uuids__:
            if ibnp_server.connection:
                ibnp_server.connection.send_add_rule(intent)
            else:
                LOG.warning('IBN not available')
        self.__uuids__[key] = rule_uuid

        # add entry
        dict.__setitem__(self, key, value)
Exemplo n.º 5
0
    def _send_add_tr(self, tenant, lvap, match, dscp, priority):

        dp = lvap.wtp.datapath

        if dp.dpid not in self.of_dpid:
            return None

        if dp.dpid not in self.dpid2ep:

            tr_ep = Endpoint(uuid4(), '', dp)

            if dp.network_ports.keys() != {1, 2}:
                raise ValueError('Network port numbers mismatch, '
                                 'please restart the WTP')

            src_vport = VirtualPort(tr_ep, dp.network_ports[1], 0)
            dst_vport = VirtualPort(tr_ep, dp.network_ports[2], 1)

            tr_ep.ports[src_vport.virtual_port_id] = src_vport
            tr_ep.ports[dst_vport.virtual_port_id] = dst_vport

            self.dpid2ep[dp.dpid] = tr_ep

        tr_ep = self.dpid2ep[dp.dpid]

        of_rule_id = uuid4()

        sta_match = Match('%s,dl_dst=%s' % (str(match), lvap.addr))

        rule = {'version': '1.0',
                'uuid': of_rule_id,
                'ttp_uuid': tr_ep.uuid,
                'ttp_vport': tr_ep.ports[1].virtual_port_id,
                'stp_uuid': tr_ep.uuid,
                'stp_vport': tr_ep.ports[0].virtual_port_id,
                'match': sta_match.match,
                'actions': [{'type': 'SET_NW_TOS',
                             'nw_tos': self.dscp2tos[str(dscp)]}],
                'priority': priority}

        self.send_add_rule(rule)

        tr_id = (match, lvap.addr)

        if tenant.tenant_id not in self.of_rules:
            self.of_rules[tenant.tenant_id] = {}

        self.of_rules[tenant.tenant_id][tr_id] = of_rule_id
    def _send_add_tr(self, tenant, lvap, match, dscp, priority):

        dp = lvap.wtp.datapath

        if dp.dpid not in self.of_dpid:
            return None

        if dp.dpid not in self.dpid2ep:

            tr_ep = Endpoint(uuid4(), '', dp)

            src_port = None
            dst_port = None

            for port in dp.network_ports.values():

                if port.iface == 'eth0' or port.iface == 'eth1':
                    src_port = port

                if port.iface == 'empower0':
                    dst_port = port

            if not src_port:
                raise KeyError('Cannot find the src network port:', port.iface)
            if not dst_port:
                raise KeyError('Cannot find the dst network port \"empower0\"')

            src_vport = VirtualPort(tr_ep, src_port, 0)
            dst_vport = VirtualPort(tr_ep, dst_port, 1)

            tr_ep.ports[src_vport.virtual_port_id] = src_vport
            tr_ep.ports[dst_vport.virtual_port_id] = dst_vport

            self.dpid2ep[dp.dpid] = tr_ep

        tr_ep = self.dpid2ep[dp.dpid]

        of_rule_id = uuid4()

        sta_match = Match('%s,dl_dst=%s' % (str(match), lvap.addr))

        rule = {'version': '1.0',
                'uuid': of_rule_id,
                'ttp_uuid': tr_ep.uuid,
                'ttp_vport': tr_ep.ports[1].virtual_port_id,
                'stp_uuid': tr_ep.uuid,
                'stp_vport': tr_ep.ports[0].virtual_port_id,
                'match': sta_match.match,
                'actions': [{'type': 'SET_NW_TOS',
                             'nw_tos': self.dscp2tos[str(dscp)]}],
                'priority': priority}

        self.send_add_rule(rule)

        of_rule_type = 'downlink'
        tr_id = (match, lvap.addr, of_rule_type)

        if tenant.tenant_id not in self.of_rules:
            self.of_rules[tenant.tenant_id] = {}

        self.of_rules[tenant.tenant_id][tr_id] = of_rule_id

        # Creating another OF rule from input port (empower0) to output port (empower0)
        of_rule_id = uuid4()

        rule = {'version': '1.0',
                'uuid': of_rule_id,
                'ttp_uuid': tr_ep.uuid,
                'ttp_vport': tr_ep.ports[1].virtual_port_id,
                'stp_uuid': tr_ep.uuid,
                'stp_vport': tr_ep.ports[1].virtual_port_id,
                'match': sta_match.match,
                'actions': [{'type': 'SET_NW_TOS',
                             'nw_tos': self.dscp2tos[str(dscp)]}],
                'priority': priority}

        self.send_add_rule(rule)

        of_rule_type = 'client_to_client'
        tr_id = (match, lvap.addr, of_rule_type)

        if tenant.tenant_id not in self.of_rules:
            self.of_rules[tenant.tenant_id] = {}

        self.of_rules[tenant.tenant_id][tr_id] = of_rule_id