Пример #1
0
    def test_run_ping_routing(self):
        n1 = nemu.Node()
        n2 = nemu.Node()
        n3 = nemu.Node()
        i1 = n1.add_if()
        i2a = n2.add_if()
        i2b = n2.add_if()
        i3 = n3.add_if()
        i1.up = i2a.up = i2b.up = i3.up = True
        l1 = nemu.Switch()
        l2 = nemu.Switch()
        l1.connect(i1)
        l1.connect(i2a)
        l2.connect(i2b)
        l2.connect(i3)
        l1.up = l2.up = True
        i1.add_v4_address('10.0.0.1', 24)
        i2a.add_v4_address('10.0.0.2', 24)
        i2b.add_v4_address('10.0.1.1', 24)
        i3.add_v4_address('10.0.1.2', 24)

        n1.add_route(prefix='10.0.1.0', prefix_len=24, nexthop='10.0.0.2')
        n3.add_route(prefix='10.0.0.0', prefix_len=24, nexthop='10.0.1.1')

        null = file('/dev/null', 'wb')
        a1 = n1.Popen(['ping', '-qc1', '10.0.1.2'], stdout=null)
        a2 = n3.Popen(['ping', '-qc1', '10.0.0.1'], stdout=null)
        self.assertEquals(a1.wait(), 0)
        self.assertEquals(a2.wait(), 0)
Пример #2
0
    def test_run_ping_tap_routing(self):
        """This test simulates a point to point connection between two hosts
        using two tap devices, and normal connections with other two, to use
        routing."""
        n1 = nemu.Node()
        n2 = nemu.Node()
        n3 = nemu.Node()
        n4 = nemu.Node()

        i1 = n1.add_if()
        i2 = n2.add_if()
        tap1 = n2.add_tap()
        tap2 = n3.add_tap()
        i3 = n3.add_if()
        i4 = n4.add_if()

        i1.up = i2.up = tap1.up = tap2.up = i3.up = i4.up = True

        l1 = nemu.Switch()
        l2 = nemu.Switch()

        l1.connect(i1)
        l1.connect(i2)
        l2.connect(i3)
        l2.connect(i4)

        l1.up = l2.up = True

        i1.add_v4_address('10.0.0.1', 24)
        i2.add_v4_address('10.0.0.2', 24)
        tap1.add_v4_address('10.0.1.1', 24)
        tap2.add_v4_address('10.0.1.2', 24)
        i3.add_v4_address('10.0.2.1', 24)
        i4.add_v4_address('10.0.2.2', 24)

        n1.add_route(prefix='10.0.1.0', prefix_len=24, nexthop='10.0.0.2')
        n1.add_route(prefix='10.0.2.0', prefix_len=24, nexthop='10.0.0.2')
        n2.add_route(prefix='10.0.2.0', prefix_len=24, nexthop='10.0.1.2')
        n3.add_route(prefix='10.0.0.0', prefix_len=24, nexthop='10.0.1.1')
        n4.add_route(prefix='10.0.1.0', prefix_len=24, nexthop='10.0.2.1')
        n4.add_route(prefix='10.0.0.0', prefix_len=24, nexthop='10.0.2.1')

        null = file('/dev/null', 'wb')
        a = n1.Popen(['ping', '-qc1', '10.0.2.2'], stdout=null)
        self._forward_packets(a, tap1, tap2)
        self.assertEquals(a.wait(), 0)
Пример #3
0
 def create_stuff():
     a = nemu.Node()
     b = nemu.Node()
     ifa = a.add_if()
     ifb = b.add_if()
     switch = nemu.Switch()
     switch.connect(ifa)
     switch.connect(ifb)
Пример #4
0
 def setUp(self):
     n1 = nemu.Node()
     n2 = nemu.Node()
     i1 = n1.add_if()
     i2 = n2.add_if()
     l = nemu.Switch()
     l.connect(i1)
     l.connect(i2)
     self.stuff = (n1, n2, i1, i2, l)
Пример #5
0
def create_topo(n, p2p, delay, jitter, bw):
    nodes = []
    interfaces = []
    links = []
    for i in range(n):
        nodes.append(nemu.Node())
    if p2p:
        interfaces = [[None]]
        for i in range(n - 1):
            a, b = nemu.P2PInterface.create_pair(nodes[i], nodes[i + 1])
            interfaces[i].append(a)
            interfaces.append([])
            interfaces[i + 1] = [b]
        interfaces[n - 1].append(None)
    else:
        for i in range(n):
            if i > 0:
                left = nodes[i].add_if()
            else:
                left = None
            if i < n - 1:
                right = nodes[i].add_if()
            else:
                right = None
            interfaces.append((left, right))
        for i in range(n - 1):
            links = nemu.Switch(bandwidth=bw, delay=delay, delay_jitter=jitter)
            links.up = True
            links.connect(interfaces[i][1])
            links.connect(interfaces[i + 1][0])
            links.append(links)

    for i in range(n):
        for j in (0, 1):
            if interfaces[i][j]:
                interfaces[i][j].up = True

    ip = ip2dec("10.0.0.1")
    for i in range(n - 1):
        interfaces[i][1].add_v4_address(dec2ip(ip), 30)
        interfaces[i + 1][0].add_v4_address(dec2ip(ip + 1), 30)
        ip += 4

    ipbase = ip2dec("10.0.0.0")
    lastnet = dec2ip(ipbase + 4 * (n - 2))
    for i in range(n - 2):
        nodes[i].add_route(prefix=lastnet,
                           prefix_len=30,
                           nexthop=dec2ip(ipbase + 4 * i + 2))
        nodes[n - 1 - i].add_route(prefix="10.0.0.0",
                                   prefix_len=30,
                                   nexthop=dec2ip(ipbase + (n - 2 - i) * 4 +
                                                  1))
    return nodes, interfaces, links
Пример #6
0
    def test_run_ping_node_if(self):
        n1 = nemu.Node()
        n2 = nemu.Node()
        i1 = n1.add_if()
        i2 = n2.add_if()
        i1.up = i2.up = True
        l = nemu.Switch()
        l.connect(i1)
        l.connect(i2)
        l.up = True
        i1.add_v4_address('10.0.0.1', 24)
        i2.add_v4_address('10.0.0.2', 24)

        null = file('/dev/null', 'wb')
        a1 = n1.Popen(['ping', '-qc1', '10.0.0.2'], stdout=null)
        a2 = n2.Popen(['ping', '-qc1', '10.0.0.1'], stdout=null)
        self.assertEquals(a1.wait(), 0)
        self.assertEquals(a2.wait(), 0)
Пример #7
0
SIZE = 5
for i in range(SIZE):
    node.append(nemu.Node(forward_X11=X))
    next_pair = (i, i + 1)
    prev_pair = (i, i - 1)
    if i < SIZE - 1:
        iface[(i, i + 1)] = nemu.NodeInterface(node[i])
        iface[(i, i + 1)].up = True
        iface[(i, i + 1)].add_v4_address(address='10.0.%d.1' % i,
                                         prefix_len=24)
    if i > 0:
        iface[(i, i - 1)] = nemu.NodeInterface(node[i])
        iface[(i, i - 1)].up = True
        iface[(i, i - 1)].add_v4_address(address='10.0.%d.2' % (i - 1),
                                         prefix_len=24)
        switch.append(nemu.Switch())
        switch[-1].connect(iface[(i, i - 1)])
        switch[-1].connect(iface[(i - 1, i)])
        switch[-1].up = True
    # Configure routing
    for j in range(SIZE - 1):
        if j in (i, i - 1):
            continue
        if j < i:
            node[i].add_route(prefix='10.0.%d.0' % j,
                              prefix_len=24,
                              nexthop='10.0.%d.1' % (i - 1))
        else:
            node[i].add_route(prefix='10.0.%d.0' % j,
                              prefix_len=24,
                              nexthop='10.0.%d.2' % i)
Пример #8
0
# each Node is a netns
node0 = nemu.Node(forward_X11=X)
node1 = nemu.Node(forward_X11=X)
node2 = nemu.Node(forward_X11=X)
print "Nodes started with pids: %s" % str((node0.pid, node1.pid, node2.pid))

# interface object maps to a veth pair with one end in a netns
if0 = nemu.NodeInterface(node0)
if1a = nemu.NodeInterface(node1)
# Between node1 and node2, we use a P2P interface
(if1b, if2) = nemu.P2PInterface.create_pair(node1, node2)

switch0 = nemu.Switch(
    bandwidth=100 * 1024 * 1024,
    delay=0.1,  # 100 ms
    delay_jitter=0.01,  # 10ms
    delay_correlation=0.25,  # 25% correlation
    loss=0.005)

# connect the interfaces
switch0.connect(if0)
switch0.connect(if1a)

# bring the interfaces up
switch0.up = if0.up = if1a.up = if1b.up = if2.up = True

# Add IP addresses
if0.add_v4_address(address='10.0.0.1', prefix_len=24)
if1a.add_v4_address(address='10.0.0.2', prefix_len=24)
if1b.add_v4_address(address='10.0.1.1', prefix_len=24)
if2.add_v4_address(address='10.0.1.2', prefix_len=24)