Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 from ryu.base import app_manager | 1 from ryu.base import app_manager |
Vasileios Papageorgiou
2017/11/29 13:49:19
How you run the file to see the graphs?
I checked
|
Vasileios Papageorgiou
2017/12/06 15:24:25
I am adding your own draft comments here so that i
|
2 from ryu.controller import ofp_event | 2 from ryu.controller import ofp_event |
3 from ryu.controller.handler import set_ev_cls | 3 from ryu.controller.handler import set_ev_cls |
4 from ryu.ofproto import ofproto_v1_0 | 4 from ryu.ofproto import ofproto_v1_0 |
5 from ryu.ofproto import ofproto_v1_3 | 5 from ryu.ofproto import ofproto_v1_3 |
6 from ryu.ofproto import ofproto_v1_2 | 6 from ryu.ofproto import ofproto_v1_2 |
7 from ryu.ofproto import ofproto_v1_2_parser | 7 from ryu.ofproto import ofproto_v1_2_parser |
8 from ryu.ofproto import ofproto_v1_3_parser | 8 from ryu.ofproto import ofproto_v1_3_parser |
9 from ryu.topology import event, switches | 9 from ryu.topology import event, switches |
10 from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER | 10 from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER |
11 import time,math, random | 11 import time,math, random |
12 from threading import Thread | 12 from threading import Thread |
13 import json, urllib2,requests, sys | 13 import json, urllib2,requests, sys |
14 from ryu.lib import hub | 14 from ryu.lib import hub |
15 from ryu.app import simple_switch_13 | 15 from ryu.app import simple_switch_13 |
16 from test import * | 16 from test import * |
17 from threading import Timer | 17 from threading import Timer |
18 import matplotlib.pyplot as plt· | 18 import matplotlib.pyplot as plt· |
19 import numpy as np | 19 import numpy as np |
20 | 20 |
21 | 21 |
22 class RPM(app_manager.RyuApp): | 22 class RPM(app_manager.RyuApp): |
23 OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] | 23 OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] |
24 | 24 |
25 def __init__(self, *args, **kwargs): | 25 def __init__(self, *args, **kwargs): |
Vasileios Papageorgiou
2017/11/29 13:49:20
too many default parameters at _init_() . Delete t
| |
26 super(RPM, self).__init__(*args, **kwargs) | 26 super(RPM, self).__init__(*args, **kwargs) |
27 self.switches = {} #switches[id]=datapath | 27 self.switches = {} #switches[id]=datapath |
28 self.sending_time={} #list with the time t0 for each switch | 28 self.sending_time={} #list with the time t0 for each switch |
29 self.reception_time={} #list of t1 | 29 self.reception_time={} #list of t1 |
30 self.RTT={} #t1-t0 | 30 self.RTT={} #t1-t0 |
31 self.maxRTT=0······· | 31 self.maxRTT=0······· |
32 self.id_maxRTT=0 | 32 self.id_maxRTT=0 |
33 self.minRTT=10 | 33 self.minRTT=10 |
34 self.id_minRTT=0 | 34 self.id_minRTT=0 |
35 self.meanRTT=0 | 35 self.meanRTT=0 |
(...skipping 16 matching lines...) Expand all Loading... | |
52 self.avgRTT302bisbis=0 | 52 self.avgRTT302bisbis=0 |
53 self.monitor_thread = hub.spawn(self._monitor) | 53 self.monitor_thread = hub.spawn(self._monitor) |
54 self.RTT302_rules={} #values of RTT302, function of number of rules | 54 self.RTT302_rules={} #values of RTT302, function of number of rules |
55 self.RTT302_flows={} #values of RTT302, function of number of flows | 55 self.RTT302_flows={} #values of RTT302, function of number of flows |
56 self.timer_rules=Timer(10,self.addRTT302_rules) | 56 self.timer_rules=Timer(10,self.addRTT302_rules) |
57 self.timer_flows=Timer(50,self.addRTT302_flows) | 57 self.timer_flows=Timer(50,self.addRTT302_flows) |
58 self.nbOfRules=0 #nb of rules sent to s302 | 58 self.nbOfRules=0 #nb of rules sent to s302 |
59 self.nbOfFlows=0 #nb od flows going through s302 | 59 self.nbOfFlows=0 #nb od flows going through s302 |
60 self.lastvalue=0 | 60 self.lastvalue=0 |
61 self.lastvaluebis=0 | 61 self.lastvaluebis=0 |
62 » » self.plotTimer_rules=Timer(169,self.plot_RTTrules) | 62 » » self.plotTimer_rules=Timer(169,self.plot_RTTrules) #timer tha t will plot the graph (RTT function of nb of rules) in 169s |
63 » » self.plotTimer_flows=Timer(330,self.plot_RTTflows) | 63 » » self.plotTimer_flows=Timer(189,self.plot_RTTflows) #timer tha t will plot the graph (RTT function of nb of rules) in 330s |
64 ················ | 64 ················ |
65 self.table_RTT_314={} | 65 self.table_RTT_314={} |
66 self.iterator_314=0 | 66 self.iterator_314=0 |
67 self.sumRTT314=0 #used for traffic | 67 self.sumRTT314=0 #used for traffic |
68 self.avgRTT314=0 | 68 self.avgRTT314=0 |
69 self.sumRTT314bis=0 #used for nb of commands | 69 self.sumRTT314bis=0 #used for nb of commands |
70 self.avgRTT314bis=0 | 70 self.avgRTT314bis=0 |
71 self.sumRTT314bisbis=0 #used for nb of flows | 71 self.sumRTT314bisbis=0 #used for nb of flows |
72 self.avgRTT314bisbis=0 | 72 self.avgRTT314bisbis=0 |
73 self.RTT314_rules={} #values of RTT302, function of number of rules | 73 self.RTT314_rules={} #values of RTT302, function of number of rules |
74 self.RTT314_flows={} #values of RTT302, function of number of flows | 74 self.RTT314_flows={} #values of RTT302, function of number of flows |
75 self.lastvalue_314=0 | 75 self.lastvalue_314=0 |
76 self.lastvaluebis_314=0 | 76 self.lastvaluebis_314=0 |
77 | 77 |
78 | 78 |
79 @set_ev_cls(event.EventSwitchEnter) #get the datapath for each swit ch· | 79 @set_ev_cls(event.EventSwitchEnter) #get the datapath for each swit ch· |
80 def get_datapaths(self, ev): | 80 def get_datapaths(self, ev): |
81 new_switch = ev.switch.dp | 81 new_switch = ev.switch.dp |
82 self.switches[new_switch.id] = ev.switch.dp | 82 self.switches[new_switch.id] = ev.switch.dp |
83 self.send_barrier_request(new_switch) | 83 self.send_barrier_request(new_switch) |
84 self.sending_time[new_switch.id]=time.time() | 84 self.sending_time[new_switch.id]=time.time() |
85 if new_switch.id == 302: | 85 if new_switch.id == 302: |
86 » » » #self.timer_rules.start() | 86 » » » #self.timer_rules.start() #launch the timer t hat will call the function addRTT302_rules in 10s |
87 » » » self.timer_flows.start() | 87 » » » self.timer_flows.start() #launch the timer tha t will call the function addRTT302_flows in 10s |
88 » » » #self.plotTimer_rules.start() | 88 » » » #self.plotTimer_rules.start() #launch the timer t hat will plot the graph (RTT function of nb of rules) in 169s |
89 » » » self.plotTimer_flows.start() | 89 » » » self.plotTimer_flows.start() #launch the timer tha t will plot the graph (RTT function of nb of rules) in 330s |
90 ················ | 90 ················ |
91 def send_barrier_request(self, datapath): #a barrier request will g et the switches to send back a barrier reply to the controller | 91 def send_barrier_request(self, datapath): #a barrier request will g et the switches to send back a barrier reply to the controller |
92 ofp_parser = datapath.ofproto_parser | 92 ofp_parser = datapath.ofproto_parser |
93 req = ofp_parser.OFPBarrierRequest(datapath) | 93 req = ofp_parser.OFPBarrierRequest(datapath) |
94 datapath.send_msg(req)··· | 94 datapath.send_msg(req)··· |
95 #------------------------------------------------------------------------------- --------------# | 95 #------------------------------------------------------------------------------- --------------# |
96 ················ | 96 ················ |
97 » def addRTT302_rules(self): #Computes avg RTT for s302 and s314 each time we add rules(here, 5 sets of rules are added each iteration(10s))» » » | 97 » def addRTT302_rules(self): #Computes avg RTT for s302 and s314 each time we add rules(here, 5 sets of rules are added each iteration(10s))» »······· |
98 » » for i in range(self.lastvalue, len(self.table_RTT_302)) : | 98 » » for i in range(self.lastvalue, len(self.table_RTT_302)) : #Get ting the sum of the new values in the list of RTTs of s302 |
99 self.sumRTT302bis=self.sumRTT302bis+self.table_RTT_302[i ] | 99 self.sumRTT302bis=self.sumRTT302bis+self.table_RTT_302[i ] |
100 » » self.avgRTT302bis=self.sumRTT302bis/(len(self.table_RTT_302)+1-s elf.lastvalue) | 100 » » self.avgRTT302bis=self.sumRTT302bis/(len(self.table_RTT_302)+1-s elf.lastvalue) #Getting the average of these values |
101 self.RTT302_rules[self.nbOfRules*20]=self.avgRTT302bis | 101 self.RTT302_rules[self.nbOfRules*20]=self.avgRTT302bis |
102 » » for i in range(self.lastvalue_314, len(self.table_RTT_314)) : | 102 » » for i in range(self.lastvalue_314, len(self.table_RTT_314)) : #Doing the same for s314 |
103 self.sumRTT314bis=self.sumRTT314bis+self.table_RTT_314[i ] | 103 self.sumRTT314bis=self.sumRTT314bis+self.table_RTT_314[i ] |
104 self.avgRTT314bis=self.sumRTT314bis/(len(self.table_RTT_314)+1-s elf.lastvalue_314) | 104 self.avgRTT314bis=self.sumRTT314bis/(len(self.table_RTT_314)+1-s elf.lastvalue_314) |
105 self.RTT314_rules[self.nbOfRules*20]=self.avgRTT314bis | 105 self.RTT314_rules[self.nbOfRules*20]=self.avgRTT314bis |
106 self.lastvalue=len(self.table_RTT_302) | 106 self.lastvalue=len(self.table_RTT_302) |
107 self.lastvalue_314=len(self.table_RTT_314) | 107 self.lastvalue_314=len(self.table_RTT_314) |
108 » » self.nbOfRules=self.nbOfRules+5 | 108 » » self.nbOfRules=self.nbOfRules+5 # increasing the frequency of nb of rules sent |
109 self.timer_rules.cancel() | 109 self.timer_rules.cancel() |
110 » » self.timer_rules=Timer(10,self.addRTT302_rules) | 110 » » self.timer_rules=Timer(10,self.addRTT302_rules) #Calling this function again in 10s |
111 self.timer_rules.start() | 111 self.timer_rules.start() |
112 | 112 |
113 » def addRTT302_flows(self): » #Computes avg RTT for s302 and s314 each time we add flows(here, 1 iperf flow added each 50s)» » »······· | 113 » def addRTT302_flows(self): » #Computes avg RTT for s302 and s314 each time we add flows(here, 1 iperf flow added each 30s)» » »······· |
Vasileios Papageorgiou
2017/11/29 13:49:20
add more comments here to make the code understand
younes.tahri3
2017/12/02 18:42:11
yes, coming soon
|
Vasileios Papageorgiou
2017/12/06 15:24:25
What do you mean by 1 iperf flow added each 30s?
younes.tahri3
2017/12/06 16:00:42
I use iperf_traffic file for this one. And in this
|
114 for i in range(self.lastvaluebis, len(self.table_RTT_302)) : | 114 for i in range(self.lastvaluebis, len(self.table_RTT_302)) : |
115 self.sumRTT302bisbis=self.sumRTT302bisbis+self.table_RTT _302[i] | 115 self.sumRTT302bisbis=self.sumRTT302bisbis+self.table_RTT _302[i] |
116 self.avgRTT302bisbis=self.sumRTT302bisbis/(len(self.table_RTT_30 2)+1-self.lastvaluebis) | 116 self.avgRTT302bisbis=self.sumRTT302bisbis/(len(self.table_RTT_30 2)+1-self.lastvaluebis) |
117 self.RTT302_flows[self.nbOfFlows]=self.avgRTT302bisbis | 117 self.RTT302_flows[self.nbOfFlows]=self.avgRTT302bisbis |
118 self.lastvaluebis=len(self.table_RTT_302) | 118 self.lastvaluebis=len(self.table_RTT_302) |
119 for i in range(self.lastvaluebis_314, len(self.table_RTT_314)) : | 119 for i in range(self.lastvaluebis_314, len(self.table_RTT_314)) : |
120 self.sumRTT314bisbis=self.sumRTT314bisbis+self.table_RTT _314[i] | 120 self.sumRTT314bisbis=self.sumRTT314bisbis+self.table_RTT _314[i] |
121 self.avgRTT314bisbis=self.sumRTT314bisbis/(len(self.table_RTT_31 4)+1-self.lastvaluebis_314) | 121 self.avgRTT314bisbis=self.sumRTT314bisbis/(len(self.table_RTT_31 4)+1-self.lastvaluebis_314) |
122 self.RTT314_flows[self.nbOfFlows]=self.avgRTT314bisbis | 122 self.RTT314_flows[self.nbOfFlows]=self.avgRTT314bisbis |
123 self.lastvaluebis_314=len(self.table_RTT_314) | 123 self.lastvaluebis_314=len(self.table_RTT_314) |
124 » » self.nbOfFlows=self.nbOfFlows+1 | 124 » » self.nbOfFlows=self.nbOfFlows+1 #Here we add a new iperf flow each 50s |
125 self.timer_flows.cancel() | 125 self.timer_flows.cancel() |
126 » » self.timer_flows=Timer(50,self.addRTT302_flows) | 126 » » self.timer_flows=Timer(30,self.addRTT302_flows) # Calling this function again in 30s |
127 self.timer_flows.start() | 127 self.timer_flows.start() |
128 | 128 |
129 #------------------------------------------------------------------------------- ----------------# | 129 #------------------------------------------------------------------------------- ----------------# |
130 def plot_RTTrules(self): #plot graph for s302 and s314 : RTT function o f nb of rules sent to s302,no rules sent ro s314 | 130 def plot_RTTrules(self): #plot graph for s302 and s314 : RTT function o f nb of rules sent to s302,no rules sent ro s314 |
Vasileios Papageorgiou
2017/11/29 13:49:19
add more comments here to make the code understand
| |
131 fig=plt.figure() | 131 fig=plt.figure() |
132 s302 = fig.add_subplot(221) | 132 s302 = fig.add_subplot(221) |
133 s314 = fig.add_subplot(222) | 133 s314 = fig.add_subplot(222) |
134 number_of_rules_per_second=list(self.RTT302_rules.keys()) | 134 number_of_rules_per_second=list(self.RTT302_rules.keys()) |
135 RTT=list(self.RTT302_rules.values()) | 135 RTT=list(self.RTT302_rules.values()) |
136 RTT314=list(self.RTT314_rules.values()) | 136 RTT314=list(self.RTT314_rules.values()) |
137 s302.plot(number_of_rules_per_second,RTT,'ro') | 137 s302.plot(number_of_rules_per_second,RTT,'ro') |
138 s302.axis([0,1600,0,2])· | 138 s302.axis([0,1600,0,2])· |
139 s314.plot(number_of_rules_per_second,RTT314,'bo') | 139 s314.plot(number_of_rules_per_second,RTT314,'bo') |
140 s314.axis([0,1600,0,2]) | 140 s314.axis([0,1600,0,2]) |
141 fig.suptitle('RTT of s302(red) and s314(blue),function of nb of rules/s sent to s302')· | 141 fig.suptitle('RTT of s302(red) and s314(blue),function of nb of rules/s sent to s302')· |
142 fig.show() | 142 fig.show() |
143 | 143 |
144 def plot_RTTflows(self): #plot graph for s302 and s314 : RTT functio n of nb of flows that go through s302. These flows don't go through s314 (cf top ology) | 144 def plot_RTTflows(self): #plot graph for s302 and s314 : RTT functio n of nb of flows that go through s302. These flows don't go through s314 (cf top ology) |
Vasileios Papageorgiou
2017/11/29 13:49:20
Have you tried to use a box plot graph as Alireza
younes.tahri3
2017/12/02 18:42:11
i haven't tried that but it doesn't change anythin
| |
145 fig=plt.figure() | 145 fig=plt.figure() |
146 s302 = fig.add_subplot(221) | 146 s302 = fig.add_subplot(221) |
147 s314 = fig.add_subplot(222) | 147 s314 = fig.add_subplot(222) |
148 number_of_flows=list(self.RTT302_flows.keys()) | 148 number_of_flows=list(self.RTT302_flows.keys()) |
149 RTT=list(self.RTT302_flows.values()) | 149 RTT=list(self.RTT302_flows.values()) |
150 RTT314=list(self.RTT314_flows.values()) | 150 RTT314=list(self.RTT314_flows.values()) |
151 s302.plot(number_of_flows,RTT,'ro') | 151 s302.plot(number_of_flows,RTT,'ro') |
152 » » s302.axis([0,5,0,6])»··· | 152 » » s302.axis([0,5,0,10])»·· |
153 s314.plot(number_of_flows,RTT314,'bo') | 153 s314.plot(number_of_flows,RTT314,'bo') |
154 » » s314.axis([0,5,0,6]) | 154 » » s314.axis([0,5,0,10]) |
155 fig.suptitle('RTT of s302(red) and s314(blue),function of nb of flows going through s302')· | 155 fig.suptitle('RTT of s302(red) and s314(blue),function of nb of flows going through s302')· |
156 fig.show() | 156 fig.show() |
157 | 157 |
158 ························ | 158 ························ |
159 #------------------------------------------------------------------------------- ---------------# | 159 #------------------------------------------------------------------------------- ---------------# |
160 | 160 |
161 def _monitor(self): #sends barrier request to all switches each period | 161 def _monitor(self): #sends barrier request to all switches each period |
162 while True:··················································································· | 162 while True:··················································································· |
163 for switch in self.switches:···· | 163 for switch in self.switches:···· |
164 self.send_barrier_request(self.switches[switch]) | 164 self.send_barrier_request(self.switches[switch]) |
(...skipping 13 matching lines...) Expand all Loading... | |
178 #print 'OFPBarrierReply from switch', switch_id, 'received' | 178 #print 'OFPBarrierReply from switch', switch_id, 'received' |
179 self.RTT[switch_id]=self.reception_time[switch_id]-self.sending_ time[switch_id] # compute the RTt················ | 179 self.RTT[switch_id]=self.reception_time[switch_id]-self.sending_ time[switch_id] # compute the RTt················ |
180 #print 'The RTT for the switch', switch_id, 'is', self.RTT[switc h_id], 'seconds' | 180 #print 'The RTT for the switch', switch_id, 'is', self.RTT[switc h_id], 'seconds' |
181 if switch_id==302: | 181 if switch_id==302: |
182 # print 'The RTT for the switch', switch_id, 'is', self.RT T[switch_id], 'seconds' | 182 # print 'The RTT for the switch', switch_id, 'is', self.RT T[switch_id], 'seconds' |
183 self.table_RTT_302[self.iterator_302]=self.RTT[switch_id ] | 183 self.table_RTT_302[self.iterator_302]=self.RTT[switch_id ] |
184 self.iterator_302=self.iterator_302+1 | 184 self.iterator_302=self.iterator_302+1 |
185 if switch_id==314: | 185 if switch_id==314: |
186 self.table_RTT_314[self.iterator_314]=self.RTT[switch_id ] | 186 self.table_RTT_314[self.iterator_314]=self.RTT[switch_id ] |
187 self.iterator_314=self.iterator_314+1 | 187 self.iterator_314=self.iterator_314+1 |
188 #if self.iterator_302==100: | |
Vasileios Papageorgiou
2017/11/29 13:49:20
Remove commented lines(188-193)
younes.tahri3
2017/12/02 18:42:11
yes, a clean code is comming soon
| |
189 # for value in self.table_RTT_302: | |
190 # self.sumRTT302=self.sumRTT302+self.table_RTT_302 [value] | |
191 # self.avgRTT302=self.sumRTT302/100 | |
192 # print self.avgRTT302 | |
193 # self.iterator_302=101 | |
194 ················ | 188 ················ |
195 ································ | 189 ································ |
196 if (self.RTT[switch_id]>self.maxRTT): #update the maxRTT | 190 if (self.RTT[switch_id]>self.maxRTT): #update the maxRTT |
197 self.maxRTT=self.RTT[switch_id] | 191 self.maxRTT=self.RTT[switch_id] |
198 self.id_maxRTT= switch_id | 192 self.id_maxRTT= switch_id |
199 if (self.RTT[switch_id]<self.minRTT): #update the minRTT | 193 if (self.RTT[switch_id]<self.minRTT): #update the minRTT |
200 self.minRTT=self.RTT[switch_id] | 194 self.minRTT=self.RTT[switch_id] |
201 self.id_minRTT= switch_id | 195 self.id_minRTT= switch_id |
202 ········ | 196 ········ |
203 if self.iterator== len(self.switches): #print the info when the controller gets the RTT for every switch | 197 if self.iterator== len(self.switches): #print the info when the controller gets the RTT for every switch |
(...skipping 12 matching lines...) Expand all Loading... | |
216 #print '------------------------------------------------ ----------------' | 210 #print '------------------------------------------------ ----------------' |
217 #print 'The switch', self.id_minRTT,'has the min RTT for this periode:', self.minRTT | 211 #print 'The switch', self.id_minRTT,'has the min RTT for this periode:', self.minRTT |
218 self.maxRTT=0 | 212 self.maxRTT=0 |
219 self.minRTT=10 | 213 self.minRTT=10 |
220 self.RTTsum=0 | 214 self.RTTsum=0 |
221 self.iterator=0 | 215 self.iterator=0 |
222 | 216 |
223 json_formatted = {"switch_id": switch_id, "RTT": self.RTT[switch _id]} | 217 json_formatted = {"switch_id": switch_id, "RTT": self.RTT[switch _id]} |
224 data = json.dumps(json_formatted) | 218 data = json.dumps(json_formatted) |
225 clen = len(data) | 219 clen = len(data) |
226 » » #req = urllib2.Request(self.url, data, {'Content-Type': 'applica tion/json', 'Content-Length': clen}) # sending the RTT to the cache | 220 » » req = urllib2.Request(self.url, data, {'Content-Type': 'applicat ion/json', 'Content-Length': clen}) # sending the RTT to the cache |
Vasileios Papageorgiou
2017/11/29 13:49:20
why lines 226-228 are commented in? Don't we need
| |
227 » » #f = urllib2.urlopen(req) | 221 » » f = urllib2.urlopen(req) |
228 » » #response = f.read() | 222 » » response = f.read() |
229 | 223 |
230 » »······· | 224 » »······· |
231 | 225 |
LEFT | RIGHT |