-
Notifications
You must be signed in to change notification settings - Fork 1
/
flownet3.py
107 lines (72 loc) · 2.96 KB
/
flownet3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python
"""
This example shows how to create an empty Mininet object
(without a topology object) and add nodes to it manually.
"""
from mininet.net import Mininet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.log import setLogLevel, info
import time
import json
import os
import socket
import Parse
def MudNet():
"Create an empty network and add nodes to it."
net = Mininet( controller=Controller )
info( '*** Adding controller\n' )
net.addController( 'c0' )
info( '*** Adding MUD Architecture Blocks\n' )
hrs = net.addHost( 'RadServer', ip='10.0.0.1' )
hms = net.addHost( 'MUDServer', ip='10.0.0.2' )
hiot = net.addHost( 'IoT Device', ip='10.0.0.3', mac = '00:00:00:00:00:02' )
h1 = net.addHost( 'h1', ip='192.168.0.1', mac = '00:00:00:00:00:01' ) #Desktop connected to home network
#h2 = net.addHost( 'h2', ip='192.168.0.2', mac = '00:00:00:00:00:02' ) #IoT Device LED Light connected to home network
h3 = net.addHost( 'h3', ip='', mac ='00:00:00:00:00:03' ) ####### IP address allowed for communication
info( '*** Adding switch\n' )
s3 = net.addSwitch( 's3' )
s4 = net.addSwitch( 's4' )
info( '*** Creating links\n' )
net.addLink( hrs, s3 )
net.addLink( hms, s3 )
net.addLink( hiot, s3 )
net.addLink( h1, s4 )
#net.addLink( h2, s4 )
net.addLink( h3, s4 )
info( '*** Starting network\n')
net.start()
hrs.cmdPrint('sudo radiusd -X > radbug.txt 2>&1 &')
hrs.cmd('sleep 15')
hms.cmdPrint('python -m SimpleHTTPServer 80 &')
hms.cmd('sleep 5')
hiot.cmdPrint('sudo echo "User-Name=Merkle, User-Password=MUDinmud, Cisco-MUD-URI=http://10.0.0.2/mud/lighting-example.json" | /usr/local/bin/radclient -x 10.0.0.1 auth testingMUD')
#s3.cmdPrint('ifconfig')
#net.stop()
os.system("sleep 2")
################################################################################
x,y = Parse.ACL()
print('Inbound access entry: '+str(x))
print('////////////////////////')
print('Outbound access entry: '+str(y))
hiot.attach('hiot-eth1')
hiot.intf('hiot-eth1').setIP('192.168.0.2')
net.addLink(s4, net.get('hiot')
net.configLinkStatus('s3', 'hiot', 'down')
net.get('h3').setIP(x[0])
h3.cmdPrint('route add default gw 128.59.105.254 h3-eth0')
h3.cmdPrint('arp -s 128.59.105.254 00:00:00:00:33:33')
h1.cmdPrint('route add default gw 192.168.0.254 h1-eth0')
h1.cmdPrint('arp -s 192.168.0.254 00:00:00:00:00:11:11')
hiot.cmdPrint('route add default gw 192.168.0.254 hiot-eth1')
hiot.cmdPrint('arp -s 192.168.0.254 00:00:00:00:00:11:11')
h3.cmdPrint('sudo python -m SimpleHTTPServer 80 &')
#os.system("more tables.txt")
os.system("ovs-ofctl add-flows s4 tables.txt")
info( '*** Running CLI\n' )
CLI( net )
info( '*** Stoping network' )
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
MudNet()