17 from topologylistener
import flow_utils, messageclasses, config
18 from multiprocessing
import Pool
26 'ignore_bandwidth':
False,
29 'src_switch':
'DE:AD:BE:EF:11:11:11:11',
30 'dst_switch':
'DE:AD:BE:EF:33:33:33:33',
34 'description':
'Test Flow #1',
35 'last_updated':
'Last Full Moon',
39 {
'switch_id':
'DE:AD:BE:EF:11:11:11:11',
'port_no': 5,
'seq_id': 1,
'segment_latency': 11},
40 {
'switch_id':
'DE:AD:BE:EF:22:22:22:22',
'port_no': 6,
'seq_id': 2,
'segment_latency': 22},
41 {
'switch_id':
'DE:AD:BE:EF:22:22:22:22',
'port_no': 7,
'seq_id': 3,
'segment_latency': 33},
42 {
'switch_id':
'DE:AD:BE:EF:33:33:33:33',
'port_no': 8,
'seq_id': 4,
'segment_latency': 44},
51 'available_bandwidth': 10000,
52 'path': [{
'switch_id':
'DE:AD:BE:EF:11:11:11:11',
'port_no': 5},
53 {
'switch_id':
'DE:AD:BE:EF:22:22:22:22',
'port_no': 6}]
58 'available_bandwidth': 20000,
59 'path': [{
'switch_id':
'DE:AD:BE:EF:22:22:22:22',
'port_no': 7},
60 {
'switch_id':
'DE:AD:BE:EF:33:33:33:33',
'port_no': 8}]
65 print(
"TEST #1 & #2 - create flow, get segments, spot check some of the values.")
66 flow_utils.store_flow(flow1)
68 result = flow_utils.fetch_flow_segments(flow1[
'flowid'], flow1[
'cookie'])
69 print(
"Validate #1 - Length of segments should be 2: %d" % len(result))
70 for i,val
in enumerate(result):
71 print(
"Validate #3.* - seq_id should be %d: is: %d" % (flow1[
'flowpath'][
'path'][i*2][
'seq_id'], val[
'seq_id']))
73 print(
"TEST #3 - create isls, validate bandwidth.")
75 mc = messageclasses.MessageItem(payload=isl)
78 for i,isl
in enumerate(messageclasses.MessageItem.fetch_isls()):
79 print(
"Validate #3.* - available_bandwidth should be %d: is: %d" % ((-3000+isls1[i][
'available_bandwidth']), isl[
'available_bandwidth']))
81 print(
"TEST #4 - remove flow, validate bandwidth.")
82 flow_utils.remove_flow(flow1)
84 result = flow_utils.fetch_flow_segments(flow1[
'flowid'], flow1[
'cookie'])
85 print(
"Validate #4.1 - should have no flow segments: %s " % result)
87 for i,isl
in enumerate(messageclasses.MessageItem.fetch_isls()):
88 print(
"Validate #4.* - available_bandwidth should be %d: is: %d" % ((isls1[i][
'available_bandwidth']), isl[
'available_bandwidth']))
94 r1a=0x2000000000000001
95 r1b=0x2000000000000002
96 f1a=0x4000000000000001
97 f1b=0x4000000000000002
101 u'timestamp': 1519103068803,
102 u'correlation_id': 1519103068744,
103 u'payload': {
u'timestamp': 1519103068797,
u'clazz':
u'org.openkilda.messaging.info.flow.FlowInfoData',
104 u'flowid':
u'c3none-1519103023077',
u'correlation_id':
u'1519103068744',
u'operation':
u'CREATE',
105 u'payload': {
u'forward': {
u'last_updated':
u'2018-02-20T05:04:28.796Z',
u'description':
u'c3none',
106 u'state':
u'ALLOCATED',
u'transit_vlan': 2,
u'ignore_bandwidth':
False,
107 u'dst_switch':
u'de:ad:be:ef:00:00:00:05',
u'flowid':
u'c3none-1519103023077',
108 u'bandwidth': 10000,
u'src_switch':
u'de:ad:be:ef:00:00:00:03',
u'cookie': f1a,
109 u'dst_port': 2,
u'src_vlan': 0,
u'dst_vlan': 0,
u'src_port': 1,
110 u'flowpath': {
u'path': [
111 {
u'seq_id': 0,
u'switch_id':
u'de:ad:be:ef:00:00:00:03',
u'port_no': 2,
u'segment_latency': 62},
112 {
u'seq_id': 1,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 1},
113 {
u'seq_id': 2,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 2,
u'segment_latency': 13},
114 {
u'seq_id': 3,
u'switch_id':
u'de:ad:be:ef:00:00:00:05',
u'port_no': 1}],
115 u'latency_ns': 75,
u'timestamp': 1519103068795,
116 u'clazz':
u'org.openkilda.messaging.info.event.PathInfoData'},
118 u'reverse': {
u'last_updated':
u'2018-02-20T05:04:28.796Z',
u'description':
u'c3none',
119 u'state':
u'ALLOCATED',
u'transit_vlan': 3,
u'ignore_bandwidth':
False,
120 u'dst_switch':
u'de:ad:be:ef:00:00:00:03',
u'flowid':
u'c3none-1519103023077',
121 u'bandwidth': 10000,
u'src_switch':
u'de:ad:be:ef:00:00:00:05',
u'cookie': r1a,
122 u'dst_port': 1,
u'src_vlan': 0,
u'dst_vlan': 0,
u'src_port': 2,
123 u'flowpath': {
u'path': [
124 {
u'seq_id': 0,
u'switch_id':
u'de:ad:be:ef:00:00:00:05',
u'port_no': 1,
u'segment_latency': 13},
125 {
u'seq_id': 1,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 2},
126 {
u'seq_id': 2,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 1,
u'segment_latency': 62},
127 {
u'seq_id': 3,
u'switch_id':
u'de:ad:be:ef:00:00:00:03',
u'port_no': 2}],
128 u'latency_ns': 75,
u'timestamp': 1519103068795,
129 u'clazz':
u'org.openkilda.messaging.info.event.PathInfoData'},
136 u'timestamp': 1519103073339,
137 u'correlation_id': 1519103073300,
138 u'payload': {
u'timestamp': 1519103073329,
u'clazz':
u'org.openkilda.messaging.info.flow.FlowInfoData',
139 u'flowid':
u'c3none-1519103023077',
u'correlation_id':
u'1519103073300',
u'operation':
u'DELETE',
140 u'payload': {
u'forward': {
u'last_updated':
u'2018-02-20T05:04:28.796Z',
u'description':
u'c3none',
141 u'state':
u'UP',
u'transit_vlan': 2,
u'ignore_bandwidth':
False,
142 u'dst_switch':
u'de:ad:be:ef:00:00:00:05',
u'flowid':
u'c3none-1519103023077',
143 u'bandwidth': 10000,
u'src_switch':
u'de:ad:be:ef:00:00:00:03',
u'cookie': f1a,
144 u'dst_port': 2,
u'src_vlan': 0,
u'dst_vlan': 0,
u'src_port': 1,
145 u'flowpath': {
u'path': [
146 {
u'seq_id': 0,
u'switch_id':
u'de:ad:be:ef:00:00:00:03',
u'port_no': 2,
u'segment_latency': 62},
147 {
u'seq_id': 1,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 1},
148 {
u'seq_id': 2,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 2,
u'segment_latency': 13},
149 {
u'seq_id': 3,
u'switch_id':
u'de:ad:be:ef:00:00:00:05',
u'port_no': 1}],
150 u'latency_ns': 75,
u'timestamp': 1519103068795,
151 u'clazz':
u'org.openkilda.messaging.info.event.PathInfoData'},
153 u'reverse': {
u'last_updated':
u'2018-02-20T05:04:28.796Z',
u'description':
u'c3none',
154 u'state':
u'UP',
u'transit_vlan': 3,
u'ignore_bandwidth':
False,
155 u'dst_switch':
u'de:ad:be:ef:00:00:00:03',
u'flowid':
u'c3none-1519103023077',
156 u'bandwidth': 10000,
u'src_switch':
u'de:ad:be:ef:00:00:00:05',
u'cookie': r1a,
157 u'dst_port': 1,
u'src_vlan': 0,
u'dst_vlan': 0,
u'src_port': 2,
158 u'flowpath': {
u'path': [
159 {
u'seq_id': 0,
u'switch_id':
u'de:ad:be:ef:00:00:00:05',
u'port_no': 1,
u'segment_latency': 13},
160 {
u'seq_id': 1,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 2},
161 {
u'seq_id': 2,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 1,
u'segment_latency': 62},
162 {
u'seq_id': 3,
u'switch_id':
u'de:ad:be:ef:00:00:00:03',
u'port_no': 2}],
163 u'latency_ns': 75,
u'timestamp': 1519103068795,
164 u'clazz':
u'org.openkilda.messaging.info.event.PathInfoData'},
172 u'timestamp': 1519167032591,
173 u'correlation_id': 1519167032523,
174 u'payload': {
u'timestamp': 1519167032580,
u'clazz':
u'org.openkilda.messaging.info.flow.FlowInfoData',
175 u'flowid':
u'c3none-1519103023077',
u'correlation_id':
u'1519167032523',
u'operation':
u'UPDATE',
176 u'payload': {
u'forward': {
u'last_updated':
u'2018-02-20T22:50:32.579Z',
u'description':
u'u3none',
177 u'state':
u'ALLOCATED',
u'transit_vlan': 4,
u'ignore_bandwidth':
False,
178 u'dst_switch':
u'de:ad:be:ef:00:00:00:05',
u'flowid':
u'c3none-1519103023077',
179 u'bandwidth': 20000,
u'src_switch':
u'de:ad:be:ef:00:00:00:03',
u'cookie': f1b,
180 u'dst_port': 2,
u'src_vlan': 0,
u'dst_vlan': 0,
u'src_port': 1,
181 u'flowpath': {
u'path': [
182 {
u'seq_id': 0,
u'switch_id':
u'de:ad:be:ef:00:00:00:03',
u'port_no': 2,
u'segment_latency': 469},
183 {
u'seq_id': 1,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 1},
184 {
u'seq_id': 2,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 2,
u'segment_latency': 357},
185 {
u'seq_id': 3,
u'switch_id':
u'de:ad:be:ef:00:00:00:05',
u'port_no': 1}],
186 u'latency_ns': 826,
u'timestamp': 1519167032578,
187 u'clazz':
u'org.openkilda.messaging.info.event.PathInfoData'},
189 u'reverse': {
u'last_updated':
u'2018-02-20T22:50:32.579Z',
u'description':
u'u3none',
190 u'state':
u'ALLOCATED',
u'transit_vlan': 5,
u'ignore_bandwidth':
False,
191 u'dst_switch':
u'de:ad:be:ef:00:00:00:03',
u'flowid':
u'c3none-1519103023077',
192 u'bandwidth': 20000,
u'src_switch':
u'de:ad:be:ef:00:00:00:05',
u'cookie': r1b,
193 u'dst_port': 1,
u'src_vlan': 0,
u'dst_vlan': 0,
u'src_port': 2,
194 u'flowpath': {
u'path': [
195 {
u'seq_id': 0,
u'switch_id':
u'de:ad:be:ef:00:00:00:05',
u'port_no': 1,
u'segment_latency': 357},
196 {
u'seq_id': 1,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 2},
197 {
u'seq_id': 2,
u'switch_id':
u'de:ad:be:ef:00:00:00:04',
u'port_no': 1,
u'segment_latency': 469},
198 {
u'seq_id': 3,
u'switch_id':
u'de:ad:be:ef:00:00:00:03',
u'port_no': 2}],
199 u'latency_ns': 826,
u'timestamp': 1519167032578,
200 u'clazz':
u'org.openkilda.messaging.info.event.PathInfoData'},
205 print(
'TEST #5 - create flow through front door (almost .. starting with dict)')
206 event_create = messageclasses.MessageItem(**create_flow)
207 event_create.handle()
211 logging.basicConfig()
212 logger = logging.getLogger(
'topologylistener.messageclasses')
214 print(
'TEST #6 - update flow through front door (almost .. starting with dict)')
215 event_delete = messageclasses.MessageItem(**update_flow)
216 event_delete.handle()
219 print(
'TEST #7 - delete flow through front door (almost .. starting with dict)')
220 event_delete = messageclasses.MessageItem(**delete_flow)
221 event_delete.handle()
225 print(
'TEST #8 - create ... A lot )')
226 print(
"==> If this fails, it will not stop, run: `ps -a | grep test_flow | cut -d ' ' -f 1 | xargs kill` ")
243 if iteration % num_proc == 0:
244 sys.stdout.write(
" {}".
format(iteration))
246 cf = copy.deepcopy(create_flow)
247 cf[
u'payload'][
u'operation'] =
"PUSH" 248 messageclasses.MessageItem(**cf).handle()
251 p = Pool(processes=num_proc)
252 p.map(do_push_alot, range(test_range))
def do_push_alot(iteration)