Jonathan Hart
Committed by Gerrit Code Review

Added materials for the SDN-IP tutorial.

Change-Id: Ib0c23d6f582bcdddfac651788529420a80d9a1d7
1 +{
2 + "addresses" : [
3 + {
4 + "dpid" : "00:00:00:00:00:00:00:a1",
5 + "port" : "1",
6 + "ips" : ["10.0.1.101/24"],
7 + "mac" : "00:00:00:00:00:01"
8 + },
9 + {
10 + "dpid" : "00:00:00:00:00:00:00:a2",
11 + "port" : "1",
12 + "ips" : ["10.0.2.101/24"],
13 + "mac" : "00:00:00:00:00:02"
14 + },
15 + {
16 + "dpid" : "00:00:00:00:00:00:00:a5",
17 + "port" : "1",
18 + "ips" : ["10.0.3.101/24"],
19 + "mac" : "00:00:00:00:00:01"
20 + },
21 + {
22 + "dpid" : "00:00:00:00:00:00:00:a6",
23 + "port" : "1",
24 + "ips" : ["10.0.4.101/24"],
25 + "mac" : "00:00:00:00:00:01"
26 + }
27 + ]
28 +}
1 +{
2 + "hosts" : [
3 + { "mac": "00:00:00:00:00:01", "vlan": -1, "location": "of:00000000000000a3/1", "ip": "10.0.1.101, 10.0.2.101, 10.0.3.101, 10.0.4.101", "annotations": { "type": "bgpSpeaker" } },
4 + { "mac": "00:00:00:00:01:01", "vlan": -1, "location": "of:00000000000000a1/1", "ip": "10.0.1.1", "annotations": { "type": "router" } },
5 + { "mac": "00:00:00:00:02:01", "vlan": -1, "location": "of:00000000000000a2/1", "ip": "10.0.2.1", "annotations": { "type": "router" } },
6 + { "mac": "00:00:00:00:03:01", "vlan": -1, "location": "of:00000000000000a5/1", "ip": "10.0.3.1", "annotations": { "type": "router" } },
7 + { "mac": "00:00:00:00:04:01", "vlan": -1, "location": "of:00000000000000a6/1", "ip": "10.0.4.1", "annotations": { "type": "router" } }
8 + ]
9 +}
1 +!
2 +hostname bgp
3 +password sdnip
4 +!
5 +!
6 +router bgp 65000
7 + bgp router-id 10.10.10.1
8 + timers bgp 3 9
9 + !
10 + neighbor 10.0.1.1 remote-as 65001
11 + neighbor 10.0.1.1 ebgp-multihop
12 + neighbor 10.0.1.1 timers connect 5
13 + neighbor 10.0.1.1 advertisement-interval 5
14 + !
15 + neighbor 10.0.2.1 remote-as 65002
16 + neighbor 10.0.2.1 ebgp-multihop
17 + neighbor 10.0.2.1 timers connect 5
18 + neighbor 10.0.2.1 advertisement-interval 5
19 + !
20 + neighbor 10.0.3.1 remote-as 65003
21 + neighbor 10.0.3.1 ebgp-multihop
22 + neighbor 10.0.3.1 timers connect 5
23 + neighbor 10.0.3.1 advertisement-interval 5
24 + !
25 + neighbor 10.0.4.1 remote-as 65004
26 + neighbor 10.0.4.1 ebgp-multihop
27 + neighbor 10.0.4.1 timers connect 5
28 + neighbor 10.0.4.1 advertisement-interval 5
29 + !
30 + ! ONOS
31 + neighbor 10.10.10.2 remote-as 65000
32 + neighbor 10.10.10.2 port 2000
33 + neighbor 10.10.10.2 timers connect 5
34 +!
35 +log stdout
1 +! BGP configuration for r1
2 +!
3 +hostname r1
4 +password sdnip
5 +!
6 +router bgp 65001
7 + bgp router-id 10.0.1.1
8 + timers bgp 3 9
9 + neighbor 10.0.1.101 remote-as 65000
10 + neighbor 10.0.1.101 ebgp-multihop
11 + neighbor 10.0.1.101 timers connect 5
12 + neighbor 10.0.1.101 advertisement-interval 5
13 + network 192.168.1.0/24
14 +!
15 +log stdout
1 +! BGP configuration for r2
2 +!
3 +hostname r2
4 +password sdnip
5 +!
6 +router bgp 65002
7 + bgp router-id 10.0.2.1
8 + timers bgp 3 9
9 + neighbor 10.0.2.101 remote-as 65000
10 + neighbor 10.0.2.101 ebgp-multihop
11 + neighbor 10.0.2.101 timers connect 5
12 + neighbor 10.0.2.101 advertisement-interval 5
13 + network 192.168.2.0/24
14 +!
15 +log stdout
1 +! BGP configuration for r3
2 +!
3 +hostname r3
4 +password sdnip
5 +!
6 +router bgp 65003
7 + bgp router-id 10.0.3.1
8 + timers bgp 3 9
9 + neighbor 10.0.3.101 remote-as 65000
10 + neighbor 10.0.3.101 ebgp-multihop
11 + neighbor 10.0.3.101 timers connect 5
12 + neighbor 10.0.3.101 advertisement-interval 5
13 + network 192.168.3.0/24
14 +!
15 +log stdout
1 +! BGP configuration for r4
2 +!
3 +hostname r4
4 +password sdnip
5 +!
6 +router bgp 65004
7 + bgp router-id 10.0.4.1
8 + timers bgp 3 9
9 + neighbor 10.0.4.101 remote-as 65000
10 + neighbor 10.0.4.101 ebgp-multihop
11 + neighbor 10.0.4.101 timers connect 5
12 + neighbor 10.0.4.101 advertisement-interval 5
13 + !network 192.168.4.0/24
14 +!
15 +log stdout
1 +{
2 + "bgpPeers" : [
3 + {
4 + "attachmentDpid" : "00:00:00:00:00:00:00:a1",
5 + "attachmentPort" : "1",
6 + "ipAddress" : "10.0.1.1"
7 + },
8 + {
9 + "attachmentDpid" : "00:00:00:00:00:00:00:a2",
10 + "attachmentPort" : "1",
11 + "ipAddress" : "10.0.2.1"
12 + },
13 + {
14 + "attachmentDpid" : "00:00:00:00:00:00:00:a5",
15 + "attachmentPort" : "1",
16 + "ipAddress" : "10.0.3.1"
17 + },
18 + {
19 + "attachmentDpid" : "00:00:00:00:00:00:00:a6",
20 + "attachmentPort" : "1",
21 + "ipAddress" : "10.0.4.1"
22 + }
23 + ],
24 + "bgpSpeakers" : [
25 + {
26 + "name" : "bgp",
27 + "attachmentDpid" : "00:00:00:00:00:00:00:a3",
28 + "attachmentPort" : "1",
29 + "macAddress" : "00:00:00:00:00:01",
30 + "interfaceAddresses" : [
31 + {
32 + "interfaceDpid" : "00:00:00:00:00:00:00:a1",
33 + "interfacePort" : "1",
34 + "ipAddress" : "10.0.1.101"
35 + },
36 + {
37 + "interfaceDpid" : "00:00:00:00:00:00:00:a2",
38 + "interfacePort" : "1",
39 + "ipAddress" : "10.0.2.101"
40 + },
41 + {
42 + "interfaceDpid" : "00:00:00:00:00:00:00:a5",
43 + "interfacePort" : "1",
44 + "ipAddress" : "10.0.3.101"
45 + },
46 + {
47 + "interfaceDpid" : "00:00:00:00:00:00:00:a6",
48 + "interfacePort" : "1",
49 + "ipAddress" : "10.0.4.101"
50 + }
51 + ]
52 + }
53 + ]
54 +}
1 +! Configuration for zebra (NB: it is the same for all routers)
2 +!
3 +hostname zebra
4 +password sdnip
5 +log stdout
1 +#!/usr/bin/python
2 +
3 +from mininet.topo import Topo
4 +from mininet.net import Mininet
5 +from mininet.cli import CLI
6 +from mininet.log import setLogLevel, info, debug
7 +from mininet.node import Host, RemoteController
8 +
9 +QUAGGA_DIR = '/usr/lib/quagga'
10 +# Must exist and be owned by quagga user (quagga:quagga by default on Ubuntu)
11 +QUAGGA_RUN_DIR = '/var/run/quagga'
12 +CONFIG_DIR = 'configs'
13 +
14 +class SdnIpHost(Host):
15 + def __init__(self, name, ip, route, *args, **kwargs):
16 + Host.__init__(self, name, ip=ip, *args, **kwargs)
17 +
18 + self.route = route
19 +
20 + def config(self, **kwargs):
21 + Host.config(self, **kwargs)
22 +
23 + debug("configuring route %s" % self.route)
24 +
25 + self.cmd('ip route add default via %s' % self.route)
26 +
27 +class Router(Host):
28 + def __init__(self, name, quaggaConfFile, zebraConfFile, intfDict, *args, **kwargs):
29 + Host.__init__(self, name, *args, **kwargs)
30 +
31 + self.quaggaConfFile = quaggaConfFile
32 + self.zebraConfFile = zebraConfFile
33 + self.intfDict = intfDict
34 +
35 + def config(self, **kwargs):
36 + Host.config(self, **kwargs)
37 + self.cmd('sysctl net.ipv4.ip_forward=1')
38 +
39 + for intf, attrs in self.intfDict.items():
40 + self.cmd('ip addr flush dev %s' % intf)
41 + if 'mac' in attrs:
42 + self.cmd('ip link set %s down' % intf)
43 + self.cmd('ip link set %s address %s' % (intf, attrs['mac']))
44 + self.cmd('ip link set %s up ' % intf)
45 + for addr in attrs['ipAddrs']:
46 + self.cmd('ip addr add %s dev %s' % (addr, intf))
47 +
48 + self.cmd('/usr/lib/quagga/zebra -d -f %s -z %s/zebra%s.api -i %s/zebra%s.pid' % (self.zebraConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))
49 + self.cmd('/usr/lib/quagga/bgpd -d -f %s -z %s/zebra%s.api -i %s/bgpd%s.pid' % (self.quaggaConfFile, QUAGGA_RUN_DIR, self.name, QUAGGA_RUN_DIR, self.name))
50 +
51 +
52 + def terminate(self):
53 + self.cmd("ps ax | egrep 'bgpd%s.pid|zebra%s.pid' | awk '{print $1}' | xargs kill" % (self.name, self.name))
54 +
55 + Host.terminate(self)
56 +
57 +
58 +class SdnIpTopo( Topo ):
59 + "SDN-IP tutorial topology"
60 +
61 + def build( self ):
62 + s1 = self.addSwitch('s1', dpid='00000000000000a1')
63 + s2 = self.addSwitch('s2', dpid='00000000000000a2')
64 + s3 = self.addSwitch('s3', dpid='00000000000000a3')
65 + s4 = self.addSwitch('s4', dpid='00000000000000a4')
66 + s5 = self.addSwitch('s5', dpid='00000000000000a5')
67 + s6 = self.addSwitch('s6', dpid='00000000000000a6')
68 +
69 + zebraConf = '%s/zebra.conf' % CONFIG_DIR
70 +
71 + # Switches we want to attach our routers to, in the correct order
72 + attachmentSwitches = [s1, s2, s5, s6]
73 +
74 + for i in range(1, 4+1):
75 + name = 'r%s' % i
76 +
77 + eth0 = { 'mac' : '00:00:00:00:0%s:01' % i,
78 + 'ipAddrs' : ['10.0.%s.1/24' % i] }
79 + eth1 = { 'ipAddrs' : ['192.168.%s.254/24' % i] }
80 + intfs = { '%s-eth0' % name : eth0,
81 + '%s-eth1' % name : eth1 }
82 +
83 + quaggaConf = '%s/quagga%s.conf' % (CONFIG_DIR, i)
84 +
85 + router = self.addHost(name, cls=Router, quaggaConfFile=quaggaConf,
86 + zebraConfFile=zebraConf, intfDict=intfs)
87 +
88 + host = self.addHost('h%s' % i, cls=SdnIpHost,
89 + ip='192.168.%s.1/24' % i,
90 + route='192.168.%s.254' % i)
91 +
92 + self.addLink(router, attachmentSwitches[i-1])
93 + self.addLink(router, host)
94 +
95 + # Set up the internal BGP speaker
96 + bgpEth0 = { 'mac':'00:00:00:00:00:01',
97 + 'ipAddrs' : ['10.0.1.101/24',
98 + '10.0.2.101/24',
99 + '10.0.3.101/24',
100 + '10.0.4.101/24',] }
101 + bgpEth1 = { 'ipAddrs' : ['10.10.10.1/24'] }
102 + bgpIntfs = { 'bgp-eth0' : bgpEth0,
103 + 'bgp-eth1' : bgpEth1 }
104 +
105 + bgp = self.addHost( "bgp", cls=Router,
106 + quaggaConfFile = '%s/quagga-sdn.conf' % CONFIG_DIR,
107 + zebraConfFile = zebraConf,
108 + intfDict=bgpIntfs )
109 +
110 + self.addLink( bgp, s3 )
111 +
112 + # Connect BGP speaker to the root namespace so it can peer with ONOS
113 + root = self.addHost( 'root', inNamespace=False, ip='10.10.10.2/24' )
114 + self.addLink( root, bgp )
115 +
116 +
117 + # Wire up the switches in the topology
118 + self.addLink( s1, s2 )
119 + self.addLink( s1, s3 )
120 + self.addLink( s2, s4 )
121 + self.addLink( s3, s4 )
122 + self.addLink( s3, s5 )
123 + self.addLink( s4, s6 )
124 + self.addLink( s5, s6 )
125 +
126 +topos = { 'sdnip' : SdnIpTopo }
127 +
128 +if __name__ == '__main__':
129 + setLogLevel('debug')
130 + topo = SDNTopo()
131 +
132 + net = Mininet(topo=topo, controller=RemoteController)
133 +
134 + net.start()
135 +
136 + CLI(net)
137 +
138 + net.stop()
139 +
140 + info("done\n")