Exemplo n.º 1
0
    def datapath_connect(self, dp_id, discovered_up_port_nums):
        """Handle Ryu datapath connection event and provision pipeline.

        Args:
            dp_id (int): datapath ID.
            discovered_up_port_nums (list): datapath ports that are up as ints.
        Returns:
            list: OpenFlow messages to send to datapath.
        """
        if self._ignore_dpid(dp_id):
            return []
        self.logger.info('Configuring %s', util.dpid_log(dp_id))
        ofmsgs = []
        ofmsgs.extend(self._add_default_flows())
        changed_ports = set([])
        for port_no in discovered_up_port_nums:
            if valve_of.ignore_port(port_no):
                continue
            changed_ports.add(port_no)
        changed_vlans = self.dp.vlans.iterkeys()
        changes = ([], changed_ports, [], changed_vlans)
        ofmsgs.extend(self._apply_config_changes(self.dp, changes))
        ofmsgs.extend(self._add_ports_and_vlans(discovered_up_port_nums))
        self.dp.running = True
        return ofmsgs
Exemplo n.º 2
0
    def _add_ports_and_vlans(self, discovered_port_nums):
        """Add all configured and discovered ports and VLANs."""
        ofmsgs = []
        all_port_nums = set()

        # add vlan ports
        for vlan in self.dp.vlans.itervalues():
            self.logger.info('Configuring VLAN %s', vlan)
            for port in vlan.get_ports():
                all_port_nums.add(port.number)
            # add mirror destination ports.
            for port in vlan.mirror_destination_ports():
                all_port_nums.add(port.number)
            # install eth_dst_table flood ofmsgs
            ofmsgs.extend(self.flood_manager.build_flood_rules(vlan))
            # add controller IPs if configured.
            ofmsgs.extend(self._add_controller_ips(vlan.controller_ips, vlan))

        # add any ports discovered but not configured
        for port_num in discovered_port_nums:
            if valve_of.ignore_port(port_num):
                continue
            if port_num not in all_port_nums:
                all_port_nums.add(port_num)

        # now configure all ports
        for port_num in all_port_nums:
            ofmsgs.extend(self.port_add(self.dp.dp_id, port_num))

        return ofmsgs
Exemplo n.º 3
0
    def _add_ports_and_vlans(self, discovered_port_nums):
        """Add all configured and discovered ports and VLANs."""
        ofmsgs = []
        all_port_nums = set()

        # add stack ports
        for port in self.dp.stack_ports:
            all_port_nums.add(port.number)

        # add vlan ports
        for vlan in self.dp.vlans.itervalues():
            ofmsgs.extend(self._add_vlan(vlan, all_port_nums))

        # add any ports discovered but not configured
        for port_num in discovered_port_nums:
            if valve_of.ignore_port(port_num):
                continue
            if port_num not in all_port_nums:
                all_port_nums.add(port_num)

        # now configure all ports
        for port_num in all_port_nums:
            ofmsgs.extend(self.port_add(self.dp.dp_id, port_num))

        return ofmsgs
Exemplo n.º 4
0
    def port_delete(self, dp_id, port_num):
        """Handle the deletion of a port.

        Args:
            dp_id (int): datapath ID.
            port_num (int): port number.
        Returns:
            list: OpenFlow messages, if any.
        """
        if self._ignore_dpid(dp_id) or valve_of.ignore_port(port_num):
            return []

        if port_num not in self.dp.ports:
            return []

        port = self.dp.ports[port_num]
        port.phys_up = False

        self.logger.warning('Port %s down', port)

        ofmsgs = []

        if not port.permanent_learn:
            ofmsgs.extend(self._delete_all_port_match_flows(port))

            # delete eth_dst rules
            ofmsgs.extend(
                self.valve_flowdel(self.dp.eth_dst_table, out_port=port_num))

        for vlan in self.dp.vlans.values():
            if port in vlan.get_ports():
                ofmsgs.extend(
                    self.flood_manager.build_flood_rules(vlan, modify=True))

        return ofmsgs
Exemplo n.º 5
0
    def datapath_connect(self, dp_id, discovered_up_port_nums):
        """Handle Ryu datapath connection event and provision pipeline.

        Args:
            dp_id (int): datapath ID.
            discovered_up_port_nums (list): datapath ports that are up as ints.
        Returns:
            list: OpenFlow messages to send to datapath.
        """
        if self._ignore_dpid(dp_id):
            return []
        self.logger.info('Configuring %s', util.dpid_log(dp_id))
        ofmsgs = []
        ofmsgs.extend(self._add_default_flows())
        changed_ports = set([])
        for port_no in discovered_up_port_nums:
            if valve_of.ignore_port(port_no):
                continue
            changed_ports.add(port_no)
        changed_vlans = self.dp.vlans.iterkeys()
        changes = ([], changed_ports, [], changed_vlans)
        ofmsgs.extend(self._apply_config_changes(self.dp, changes))
        ofmsgs.extend(self._add_ports_and_vlans(discovered_up_port_nums))
        self.dp.running = True
        return ofmsgs
Exemplo n.º 6
0
    def _add_ports_and_vlans(self, discovered_port_nums):
        """Add all configured and discovered ports and VLANs."""
        ofmsgs = []
        all_port_nums = set()

        # add stack ports
        for port in self.dp.stack_ports:
            all_port_nums.add(port.number)

        # add vlan ports
        for vlan in self.dp.vlans.itervalues():
            ofmsgs.extend(self._add_vlan(vlan, all_port_nums))

        # add any ports discovered but not configured
        for port_num in discovered_port_nums:
            if valve_of.ignore_port(port_num):
                continue
            if port_num not in all_port_nums:
                all_port_nums.add(port_num)

        # now configure all ports
        for port_num in all_port_nums:
            ofmsgs.extend(self.port_add(self.dp.dp_id, port_num))

        return ofmsgs
Exemplo n.º 7
0
    def datapath_connect(self, dp_id, discovered_up_port_nums):
        """Handle Ryu datapath connection event and provision pipeline.

        Args:
            dp_id (int): datapath ID.
            discovered_up_port_nums (list): datapath ports that are up as ints.
        Returns:
            list: OpenFlow messages to send to datapath.
        """
        if self._ignore_dpid(dp_id):
            return []
        self.logger.info('Configuring %s', util.dpid_log(dp_id))
        ofmsgs = []
        # Add the default meter to ofmsgs, assumes that meter and Controller meter are supported (Jayden Hewer)
        #ofmsgs.extend(self._add_default_meters())
        # The line above is commented out as Lagopus does not support this feature.
        ofmsgs.extend(self._add_simple_meter())
        ofmsgs.extend(self._add_default_flows())
        changed_ports = set([])
        for port_no in discovered_up_port_nums:
            if valve_of.ignore_port(port_no):
                continue
            changed_ports.add(port_no)
        changed_vlans = self.dp.vlans.iterkeys()
        changes = ([], changed_ports, [], changed_vlans)
        ofmsgs.extend(self._apply_config_changes(self.dp, changes))
        ofmsgs.extend(self._add_ports_and_vlans(discovered_up_port_nums))
        self.dp.running = True
        return ofmsgs
Exemplo n.º 8
0
    def _known_up_dpid_and_port(self, dp_id, in_port):
        """Returns True if datapath and port are known and running.

        Args:
            dp_id (int): datapath ID.
            in_port (int): port number.
        Returns:
            bool: True if datapath and port are known and running.
        """
        if (not self._ignore_dpid(dp_id) and not valve_of.ignore_port(in_port) and
                self.dp.running and in_port in self.dp.ports):
            return True
        return False
Exemplo n.º 9
0
    def _known_up_dpid_and_port(self, dp_id, in_port):
        """Returns True if datapath and port are known and running.

        Args:
            dp_id (int): datapath ID.
            in_port (int): port number.
        Returns:
            bool: True if datapath and port are known and running.
        """
        if (not self._ignore_dpid(dp_id) and not valve_of.ignore_port(in_port) and
                self.dp.running and in_port in self.dp.ports):
            return True
        return False
Exemplo n.º 10
0
    def port_add(self, dp_id, port_num):
        """Handle the addition of a port.

        Args:
            dp_id (int): datapath ID.
            port_num (int): port number.
        Returns:
            list: OpenFlow messages, if any.
        """
        if self._ignore_dpid(dp_id) or valve_of.ignore_port(port_num):
            return []

        if port_num not in self.dp.ports:
            self.logger.info(
                'Ignoring port:%u not present in configuration file', port_num)
            return []

        port = self.dp.ports[port_num]
        self.logger.info('Port %s added', port)
        port.phys_up = True

        if not port.running():
            return []

        ofmsgs = []
        self.logger.info('Sending config for port %s', port)

        # Delete all flows previously matching this port
        ofmsgs.extend(self._delete_all_port_match_flows(port))

        # Port is a mirror destination; drop all input packets
        if port.mirror_destination:
            ofmsgs.append(self.valve_flowdrop(
                self.dp.vlan_table,
                match=self.valve_in_match(self.dp.vlan_table, in_port=port_num),
                priority=self.dp.highest_priority))
            return ofmsgs

        # Add ACL if any
        acl_ofmsgs, forwarding_table = self._port_add_acl(port_num)
        ofmsgs.extend(acl_ofmsgs)

        # Add mirroring if any
        mirror_act = []
        if port.mirror:
            mirror_act = [valve_of.output_port(port.mirror)]

        # Add port/to VLAN rules.
        ofmsgs.extend(self._port_add_vlans(port, forwarding_table, mirror_act))

        return ofmsgs
Exemplo n.º 11
0
    def port_delete(self, dp_id, port_num):
        """Handle the deletion of a port.

        Args:
            dp_id (int): datapath ID.
            port_num (int): port number.
        Returns:
            list: OpenFlow messages, if any.
        """
        if self._ignore_dpid(dp_id) or valve_of.ignore_port(port_num):
            return []

        if port_num not in self.dp.ports:
            return []

        port = self.dp.ports[port_num]
        port.phys_up = False

        self.logger.warning('Port %s down', port)

        ofmsgs = []

        if not port.permanent_learn:
            ofmsgs.extend(self._delete_all_port_match_flows(port))

            # delete eth_dst rules
            ofmsgs.extend(self.valve_flowdel(
                self.dp.eth_dst_table,
                out_port=port_num))

        for vlan in self.dp.vlans.values():
            if port in vlan.get_ports():
                ofmsgs.extend(self.flood_manager.build_flood_rules(
                    vlan, modify=True))

        return ofmsgs
Exemplo n.º 12
0
    def port_add(self, dp_id, port_num, modify=False):
        """Handle the addition of a port.

        Args:
            dp_id (int): datapath ID.
            port_num (int): port number.
        Returns:
            list: OpenFlow messages, if any.
        """
        if self._ignore_dpid(dp_id) or valve_of.ignore_port(port_num):
            return []

        if port_num not in self.dp.ports:
            self.logger.info(
                'Ignoring port:%u not present in configuration file', port_num)
            return []

        port = self.dp.ports[port_num]
        port.phys_up = True

        ofmsgs = []
        if modify:
            # delete all rules related to this port
            tables = [self.dp.vlan_table, self.dp.acl_table,
                      self.dp.eth_src_table, self.dp.flood_table]
            for table_id in tables:
                ofmsgs.extend(self.valve_flowdel(
                    table_id,
                    self.valve_in_match(table_id, in_port=port_num)))

            if not port.permanent_learn:
                # delete eth_dst rules
                ofmsgs.extend(self.valve_flowdel(
                    self.dp.eth_dst_table,
                    out_port=port_num))
            self.logger.info('Port %s modified', port)
        else:
            self.logger.info('Port %s added', port)

        if not port.running():
            return ofmsgs

        self.logger.info('Sending config for port %s', port)

        # Delete all flows previously matching this port
        ofmsgs.extend(self._delete_all_port_match_flows(port))

        # Port is a mirror destination; drop all input packets
        if port.mirror_destination:
            ofmsgs.append(self.valve_flowdrop(
                self.dp.vlan_table,
                match=self.valve_in_match(self.dp.vlan_table, in_port=port_num),
                priority=self.dp.highest_priority))
            return ofmsgs

        # Add ACL if any.
        acl_ofmsgs, forwarding_table = self._port_add_acl(port_num)
        ofmsgs.extend(acl_ofmsgs)

        # If this is a stacking port, accept all VLANs (came from another FAUCET)
        if port.stack is not None:
            ofmsgs.append(self.valve_flowmod(
                self.dp.vlan_table,
                match=self.valve_in_match(self.dp.vlan_table, in_port=port_num),
                priority=self.dp.low_priority,
                inst=[valve_of.goto_table(forwarding_table)]))
            return ofmsgs

        # Add mirroring if any
        mirror_act = []
        if port.mirror:
            mirror_act = [valve_of.output_port(port.mirror)]

        # Add port/to VLAN rules.
        ofmsgs.extend(self._port_add_vlans(port, forwarding_table, mirror_act))

        return ofmsgs
Exemplo n.º 13
0
    def port_add(self, dp_id, port_num, modify=False):
        """Handle the addition of a port.

        Args:
            dp_id (int): datapath ID.
            port_num (int): port number.
        Returns:
            list: OpenFlow messages, if any.
        """
        if self._ignore_dpid(dp_id) or valve_of.ignore_port(port_num):
            return []

        if port_num not in self.dp.ports:
            self.logger.info(
                'Ignoring port:%u not present in configuration file', port_num)
            return []

        port = self.dp.ports[port_num]
        port.phys_up = True

        ofmsgs = []
        if modify:
            if not port.permanent_learn:
                # delete eth_dst rules
                ofmsgs.extend(self.valve_flowdel(
                    self.dp.eth_dst_table,
                    out_port=port_num))
            self.logger.info('Port %s modified', port)
        else:
            self.logger.info('Port %s added', port)

        if not port.running():
            return ofmsgs

        self.logger.info('Sending config for port %s', port)

        # Delete all flows previously matching this port
        ofmsgs.extend(self._delete_all_port_match_flows(port))

        # Port is a mirror destination; drop all input packets
        if port.mirror_destination:
            ofmsgs.append(self.valve_flowdrop(
                self.dp.vlan_table,
                match=self.valve_in_match(self.dp.vlan_table, in_port=port_num),
                priority=self.dp.highest_priority))
            return ofmsgs

        # Add ACL if any.
        acl_ofmsgs = self._port_add_acl(port_num)
        ofmsgs.extend(acl_ofmsgs)

        # If this is a stacking port, accept all VLANs (came from another FAUCET)
        if port.stack is not None:
            ofmsgs.append(self.valve_flowmod(
                self.dp.vlan_table,
                match=self.valve_in_match(self.dp.vlan_table, in_port=port_num),
                priority=self.dp.low_priority,
                inst=[valve_of.goto_table(self.dp.eth_src_table)]))
            for vlan in self.dp.vlans.values():
                ofmsgs.extend(self.flood_manager.build_flood_rules(vlan))
        else:
            mirror_act = []
            # Add mirroring if any
            if port.mirror:
                mirror_act = [valve_of.output_port(port.mirror)]
            # Add port/to VLAN rules.
            ofmsgs.extend(self._port_add_vlans(port, mirror_act))
        return ofmsgs