- ns_qouter = str(vlan) + '-qrouter'
- qrouter_ovs_veth = str(vlan) + '-vethOQ'
- qrouter_ns_veth = str(vlan) + '-vethQO'
-
- # Create NS
- command = 'sudo ip netns add ' + ns_qouter
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()
-
- # Create pait veth
- command = 'sudo ip link add {} type veth peer name {}'.format(qrouter_ns_veth, qrouter_ovs_veth)
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()
-
- # up ovs veth interface
- command = 'sudo ip link set dev {} up'.format(qrouter_ovs_veth)
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()
-
- # add ovs veth to ovs br-int
- command = 'sudo ovs-vsctl add-port br-int {} tag={}'.format(qrouter_ovs_veth, vlan)
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()
-
- # add veth to ns
- command = 'sudo ip link set {} netns {}'.format(qrouter_ns_veth, ns_qouter)
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()
-
- # up ns loopback
- command = 'sudo ip netns exec {} ip link set dev lo up'.format(ns_qouter)
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()
-
- # up ns veth
- command = 'sudo ip netns exec {} ip link set dev {} up'.format(ns_qouter, qrouter_ns_veth)
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()
-
- from netaddr import IPNetwork
- ip_tools = IPNetwork(dhcp_cidr)
- cidr_len = ip_tools.prefixlen
-
- # set gw to ns veth
- command = 'sudo ip netns exec {} ip address add {}/{} dev {}'.format(ns_qouter, gateway, cidr_len, qrouter_ns_veth)
- self.logger.debug("command: " + command)
- (_, stdout, _) = self.ssh_conn.exec_command(command)
- content = stdout.read()