forked from dlinknctu/mininet
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopennet.py
More file actions
93 lines (71 loc) · 2.56 KB
/
opennet.py
File metadata and controls
93 lines (71 loc) · 2.56 KB
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
#!/usr/bin/python
import os
import socket
import fcntl
import struct
import ns.netanim
import ns.csma
import ns.wifi
def getIntfAddr (intf):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
n = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', intf[:15]))[20:24]
return socket.inet_ntoa(n)
def checkDictionaryPath(path):
""" Check dictionary exist or not, if not create it """
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
return path
class Netanim( object ):
def __init__(self, path="/tmp/xml/wifi-wired-bridged4.xml", nodes=None, packetmetadata=True):
self.path = path
self.packetmetadata = packetmetadata
self.nodes = nodes
self.netanim = self.Netanim()
def __str__(self):
return repr(self)
def __repr__(self):
path_str = "Netanim path: %s" % self.getNetanimPath()
return path_str
def Netanim(self):
""" Enable netanim output """
checkDictionaryPath(self.path)
netanim = ns.netanim.AnimationInterface(self.path)
netanim.EnablePacketMetadata(self.packetmetadata)
return netanim
def getNetanimPath(self):
return self.path
def UpdateNodeDescription(self, node, desc):
self.netanim.UpdateNodeDescription(node, desc)
return True
def UpdateNodeColor(self, node, r, g, b):
self.netanim.UpdateNodeColor(node, r, g, b)
return True
class Pcap( object ):
def __init__(self, wifi_pcap_path="/tmp/pcap/wifi", csma_pcap_path="/tmp/pcap/csma"):
self.wifi_pcap_path = wifi_pcap_path
self.csma_pcap_path = csma_pcap_path
def __str__(self):
return repr(self)
def __repr__(self):
pcap_path = "Wifi pcap path: %s\nCSMA pcap path:%s" % (self.getWifiPath(), self.getCSMAPath())
return pcap_path
def setWifiPath(self, path):
checkDictionaryPath(path)
self.wifi_pcap_path = checkDictionaryPath(path)
return True
def setCSMAPath(self, path):
checkDictionaryPath(path)
self.csma_pcap_path = path
return True
def getWifiPath(self):
return self.wifi_pcap_path
def getCSMAPath(self):
return self.csma_pcap_path
def enable(self):
""" Setting Wifi pcap """
self.setWifiPath(self.wifi_pcap_path)
ns.wifi.YansWifiPhyHelper().Default().EnablePcapAll(self.wifi_pcap_path)
""" Setting CSMA pcap """
self.setCSMAPath(self.csma_pcap_path)
ns.csma.CsmaHelper().EnablePcapAll(self.csma_pcap_path)
return True