Revision 163b30ce

View differences:

confFileGenerator/Node.py
23 23
import os.path
24 24

  
25 25

  
26
BRIDGE = "br-iof"
27
BRIDGE_CONF = """
28
exists=`brctl show | grep {bridge}`
29
if [ -z "$exists" ]; then
30
    brctl addbr {bridge}
31
fi
32
brctl stp   {bridge} off
33
ip link set dev {bridge} up
34
""".format(bridge=BRIDGE)
35

  
36
NS_CONF = """
37
ip netns add ns{host}
38
ip netns exec ns{host} ip link set lo up
39
"""
40

  
41
TAP_CONF = """
42
# create a port pair
43
ip link add tap{host} type veth peer name br-tap{host}
44
# attach one side to linuxbridge
45
brctl addif {bridge} br-tap{host}
46
# attach the other side to namespace
47
ip link set tap{host} netns ns{host}
48
# set the ports to up
49
ip netns exec ns{host} ip link set dev tap{host} up
50
ip link set dev br-tap{host} up
51
"""
52

  
53
IP_CONF = """
54
ip netns exec ns{host} ip addr add {ip}/30 dev tap{host}
55
"""
56

  
57
IF_BRIDGE = """
58
ip link set {interface} up
59
brctl addif {bridge} {interface}
60
"""
61

  
62

  
26 63
class Node:
27 64
    nodeIpAddr_network = ipaddress.ip_network(u'200.0.0.0/8')
28 65
    counter_node = 1
......
32 69
    counter_networks = 1
33 70
    ClientList = []
34 71

  
35
    def __init__(self, name, node_type, out_folder, mrai='0'):
72
    def __init__(self, name, node_type, out_folder, mrai='0',
73
                 interface="enp0s9"):
36 74
        self.name = name
37 75
        self.type = node_type
38 76
        self.mrai = int(float(mrai)*1000)
77
        self.intf = interface
39 78

  
40 79
        if self.type == "C":
41 80
            Node.ClientList.append(int(self.name)+1)
......
117 156
        output = "{}_conf.sh".format(host)
118 157
        # TODO: before this: assign this AS to one testbed node
119 158
        # TODO: read interface name from device configuration
120
        ip_conf = "ip addr add {}/30 dev enp0s8\n"
121 159
        with open(join(self.outFolder, output), "w") as out_file:
160
            out_file.write(BRIDGE_CONF)
161
            out_file.write(NS_CONF.format(host=host))
162
            out_file.write(TAP_CONF.format(host=host, bridge=BRIDGE))
163
            out_file.write(IF_BRIDGE.format(bridge=BRIDGE, interface=self.intf))
122 164
            for _,ip in self.eth_dict.items():
123
                out_file.write(ip_conf.format(str(ip)))
165
                out_file.write(IP_CONF.format(host=host, ip=str(ip)))
124 166

  
125 167
    def delete_export_file(self):
126 168
        if os.path.isfile(self.outFolder + self.sessionExporterFile_name):

Also available in: Unified diff