Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        VPNInstanceDataplane.__init__(self, *args)

        self.namespaceId = self._get_namespace_from_network()

        self.log.info("VRF %d: Initializing network namespace %s",
                      self.instanceId, self.namespaceId)
        if self._namespace_exists():
            self.log.debug("VRF netns already exists, flushing MPLS routes...")
            # Flush all MPLS routes in network namespace
            (output, _) = self._runCommand("ip netns exec %s ip route show" %
                                           self.namespaceId)
            for line in output:
                if "mpls" in line:
                    self._runCommand("ip netns exec %s ip route del %s" %
                                     (self.namespaceId, line))
        else:
            self.log.debug("VRF network namespace doesn't exist, creating...")
            # Create network namespace
            self._runCommand("ip netns add %s" % self.namespaceId)

            # Set up mpls0 interface
            self._runCommand("ip netns exec %s ip link set mpls0 up" %
                             self.namespaceId)

            # Set up veth pair devices
            (tap_dev, ns_dev) = self._create_veth_pair()

            # Retrieve broadcast IP address
            ip = IPNetwork("%s/%s" % (self.gatewayIP, self.mask))
            broadcastIP = str(ip.broadcast)

            # Set up bridge network namespace interface as gateway
            self._runCommand("ip netns exec %s ip addr add %s/%s broadcast "
                             "%s dev %s" % (self.namespaceId, self.gatewayIP,
                                            self.mask, broadcastIP, ns_dev),
                             raiseExceptionOnError=False)

            # Setup IP forwarding
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys/"
                             "net/ipv4/ip_forward\"" % self.namespaceId)
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys/net"
                             "/ipv4/conf/all/forwarding\"" % self.namespaceId)

            # Setup ARP proxying
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys/net"
                             "/ipv4/conf/%s/proxy_arp\"" %
                             (self.namespaceId, ns_dev))
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys/net"
                             "/ipv4/conf/%s/proxy_arp_pvlan\"" %
                             (self.namespaceId, ns_dev))

            # Create bridge and adds tap interface on it
            self._create_namespace_bridge(tap_dev)
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        VPNInstanceDataplane.__init__(self, *args)

        self.namespaceId = self._get_namespace_from_network()

        self.log.info("VRF %d: Initializing network namespace %s", self.instanceId, self.namespaceId)
        if self._namespace_exists():
            self.log.debug("VRF netns already exists, flushing MPLS routes...")
            # Flush all MPLS routes in network namespace
            (output, _) = self._runCommand("ip netns exec %s ip route show" % self.namespaceId)
            for line in output:
                if "mpls" in line:
                    self._runCommand("ip netns exec %s ip route del %s" % (self.namespaceId, line))
        else:
            self.log.debug("VRF network namespace doesn't exist, creating...")
            # Create network namespace
            self._runCommand("ip netns add %s" % self.namespaceId)

            # Set up mpls0 interface
            self._runCommand("ip netns exec %s ip link set mpls0 up" % self.namespaceId)

            # Set up veth pair devices
            (tap_dev, ns_dev) = self._create_veth_pair()

            # Retrieve broadcast IP address
            ip = IPNetwork("%s/%s" % (self.gatewayIP, self.mask))
            broadcastIP = str(ip.broadcast)

            # Set up bridge network namespace interface as gateway
            self._runCommand(
                "ip netns exec %s ip addr add %s/%s broadcast "
                "%s dev %s" % (self.namespaceId, self.gatewayIP, self.mask, broadcastIP, ns_dev),
                raiseExceptionOnError=False,
            )

            # Setup IP forwarding
            self._runCommand('ip netns exec %s sh -c "echo 1 > /proc/sys/' 'net/ipv4/ip_forward"' % self.namespaceId)
            self._runCommand(
                'ip netns exec %s sh -c "echo 1 > /proc/sys/net' '/ipv4/conf/all/forwarding"' % self.namespaceId
            )

            # Setup ARP proxying
            self._runCommand(
                'ip netns exec %s sh -c "echo 1 > /proc/sys/net' '/ipv4/conf/%s/proxy_arp"' % (self.namespaceId, ns_dev)
            )
            self._runCommand(
                'ip netns exec %s sh -c "echo 1 > /proc/sys/net'
                '/ipv4/conf/%s/proxy_arp_pvlan"' % (self.namespaceId, ns_dev)
            )

            # Create bridge and adds tap interface on it
            self._create_namespace_bridge(tap_dev)
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        VPNInstanceDataplane.__init__(self, *args)

        self.arpNetNS = ("%s%d" %
                         (ARPNETNS_PREFIX, self.instanceId))[:LINUX_DEV_LEN]

        # Initialize dict where we store info on OVS ports (port numbers and
        # bound IP address)
        self._ovsPortInfo = dict()

        # Find ethX MPLS interface MAC address
        if not self.driver.useGRE:
            self.mplsIfMacAddress = net_utils.get_device_mac(
                self._runCommand, self.driver.mpls_interface)
        else:
            self.mplsIfMacAddress = None

        self.bridge = self.driver.bridge

        self.fallback = None
        self.push_vlan_action = None

        if self.driver.proxy_arp:
            self._initARPNetNS()

        # Create VRF-specific OVS patch ports
        self.log.debug(
            "Creating VRF patch ports and mapping traffic to gateway...")
        self.patchPortIn = 'ipvpn%d-pp-in' % self.instanceId
        self.patchPortOut = 'ipvpn%d-pp-out' % self.instanceId
        self._runCommand("ovs-vsctl --may-exist add-port %s %s -- "
                         "set Interface %s type=patch options:peer=%s" %
                         (self.bridge, self.patchPortIn, self.patchPortIn,
                          self.patchPortOut))
        self._runCommand("ovs-vsctl --may-exist add-port %s %s -- "
                         "set Interface %s type=patch options:peer=%s" %
                         (self.bridge, self.patchPortOut, self.patchPortOut,
                          self.patchPortIn))

        self.patchPortInNumber = self.driver.find_ovs_port(self.patchPortIn)
        self.patchPortOutNumber = self.driver.find_ovs_port(self.patchPortOut)

        if self.driver.proxy_arp:
            # Map traffic from patch port to gateway
            self._ovs_flow_add(
                'in_port=%s,ip,nw_dst=%s' %
                (self.patchPortInNumber, self.gatewayIP),
                'output:%s' % self.arpNetNSPort, self.driver.ovs_table_vrfs)
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        VPNInstanceDataplane.__init__(self, *args)

        self.arpNetNS = ("%s-vrf%d" %
                         (ARPNETNS_PREFIX, self.instanceId))[:LINUX_DEV_LEN]

        # Initialize dict where we store info on OVS ports (port numbers and
        # bound IP address)
        self._ovsPortInfo = dict()

        # Find ethX MPLS interface MAC address
        if not self.driver.useGRE:
            self.mplsIfMacAddress = self._find_dev_mac_address(
                self.driver.mpls_interface)
        else:
            self.mplsIfMacAddress = None

        self.bridge = self.driver.bridge

        self.log.info("VRF %d: Initializing network namespace %s for ARP "
                      "proxing", self.instanceId, self.arpNetNS)
        # Get names of veth pair devices between OVS and network namespace
        ovsbr_to_proxyarp_ns = self.driver.get_ovsbr2arpns_if(
            self.arpNetNS)

        if not self._arpNetNsExists():
            self.log.debug("VRF network namespace doesn't exist, creating...")
            # Create network namespace
            self._runCommand("ip netns add %s" % self.arpNetNS)

            # Set up veth pair devices between OVS and ARP network namespace
            self._create_arpnetns_veth_pair(ovsbr_to_proxyarp_ns,
                                            PROXYARP2OVS_IF)

            # Retrieve broadcast IP address
            ip = IPNetwork("%s/%s" % (self.gatewayIP, self.mask))
            broadcastIP = str(ip.broadcast)

            # Set up network namespace interface as gateway
            self._runCommand("ip netns exec %s ip addr add %s/%s broadcast %s"
                             " dev %s" %
                             (self.arpNetNS, self.gatewayIP,
                              self.mask, broadcastIP, PROXYARP2OVS_IF),
                             raiseExceptionOnError=True)

            # Setup IP forwarding
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys"
                             "/net/ipv4/ip_forward\"" % self.arpNetNS)
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys/net"
                             "/ipv4/conf/all/forwarding\"" % self.arpNetNS)

            # Setup ARP proxying
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys/net"
                             "/ipv4/conf/%s/proxy_arp\"" %
                             (self.arpNetNS, PROXYARP2OVS_IF))
            self._runCommand("ip netns exec %s sh -c \"echo 1 > /proc/sys/net"
                             "/ipv4/conf/%s/proxy_arp_pvlan\"" %
                             (self.arpNetNS, PROXYARP2OVS_IF))
        else:
            self.log.debug("VRF network namespace already exists...")

        # OVS port number for the port toward the proxy ARP netns
        self.arpNetNSPort = self.driver.find_ovs_port(ovsbr_to_proxyarp_ns)

        # Find gateway ("network namespace to OVS" port) MAC address
        self.gwMacAddress = self._find_ns_dev_mac_address(
            self.arpNetNS, PROXYARP2OVS_IF)

        # Create OVS patch ports
        self.log.debug(
            "Creating VRF patch ports and mapping traffic to gateway...")
        self.patchPortIn = 'ipvpn%d-pp-in' % self.instanceId
        self.patchPortOut = 'ipvpn%d-pp-out' % self.instanceId
        self._runCommand("ovs-vsctl --may-exist add-port %s %s -- "
                         "set Interface %s type=patch options:peer=%s" %
                         (self.bridge, self.patchPortIn,
                          self.patchPortIn, self.patchPortOut))
        self._runCommand("ovs-vsctl --may-exist add-port %s %s -- "
                         "set Interface %s type=patch options:peer=%s" %
                         (self.bridge, self.patchPortOut,
                          self.patchPortOut, self.patchPortIn))

        self.patchPortInNumber = self.driver.find_ovs_port(self.patchPortIn)
        self.patchPortOutNumber = self.driver.find_ovs_port(self.patchPortOut)
        # Map traffic from patch port to gateway
        self._ovs_flow_add('in_port=%s,ip,nw_dst=%s' % (self.patchPortInNumber,
                                                        self.gatewayIP),
                           'output:%s' % self.arpNetNSPort,
                           self.driver.ovs_table_vrfs)