18 from topologylistener
import exc
19 from topologylistener
import isl_utils
20 from topologylistener
import messageclasses
21 from topologylistener
import model
24 ISL_STATUS_ACTIVE =
'active' 25 ISL_STATUS_INACTIVE =
'inactive' 26 ISL_STATUS_MOVED =
'moved' 28 ISL_STATUS_PROPS_DOWN = {
29 'actual': ISL_STATUS_INACTIVE,
'status': ISL_STATUS_INACTIVE}
30 ISL_STATUS_PROPS_HALF_UP = {
31 'actual': ISL_STATUS_ACTIVE,
'status': ISL_STATUS_INACTIVE}
32 ISL_STATUS_PROPS_UP = {
'actual': ISL_STATUS_ACTIVE,
'status': ISL_STATUS_ACTIVE}
33 ISL_STATUS_PROPS_MOVED = {
34 'actual': ISL_STATUS_MOVED,
'status': ISL_STATUS_MOVED}
36 neo4j_connect = share.env.neo4j_connect
41 'src_switch': source.dpid,
42 'src_port': source.port,
43 'dst_switch': dest.dpid,
44 'dst_port': dest.port,
47 p[
'link_props'] = match.copy()
48 p[
'link_props'].update(payload)
51 'MERGE (subject:link_props {\n' 52 ' src_switch: $src_switch,' 53 ' src_port: $src_port,' 54 ' dst_switch: $dst_switch,' 55 ' dst_port: $dst_port})\n' 56 'SET subject = $link_props')
62 'clazz': messageclasses.MT_SWITCH,
65 'address':
'172.16.0.64',
66 'hostname':
'test-sw-{}'.
format(dpid.replace(
':',
'')),
67 'description':
'test switch',
68 'controller':
'172.16.0.1'}
69 command = share.command(payload)
75 'clazz': messageclasses.MT_SWITCH,
78 'address':
'172.16.0.64',
79 'hostname':
'test-sw-{}'.
format(dpid.replace(
':',
'')),
80 'description':
'test switch',
81 'controller':
'172.16.0.1'}
82 command = share.command(payload)
88 'clazz': messageclasses.MT_PORT,
90 'switch_id': endpoint.dpid,
91 'port_no': endpoint.port}
92 command = share.command(payload)
99 share.feed_isl_discovery(forward)
100 share.feed_isl_discovery(forward.reversed())
104 command = share.command({
105 'clazz': messageclasses.MT_ISL,
109 'available_bandwidth': 1000,
112 'switch_id': source.dpid,
113 'port_no': source.port}]})
118 command = share.command({
119 'clazz': messageclasses.MT_ISL,
123 'available_bandwidth': 1000,
126 'switch_id': isl.source.dpid,
127 'port_no': isl.source.port
130 'switch_id': isl.dest.dpid,
131 'port_no': isl.dest.port
145 reverse = forward.reversed()
150 status_down = {
'actual': ISL_STATUS_INACTIVE,
'status': ISL_STATUS_INACTIVE}
151 status_half_up = {
'actual': ISL_STATUS_ACTIVE,
'status': ISL_STATUS_INACTIVE}
152 status_up = {
'actual': ISL_STATUS_ACTIVE,
'status': ISL_STATUS_ACTIVE}
155 self.assertTrue(share.feed_isl_discovery(forward))
160 self.assertTrue(share.feed_isl_discovery(reverse))
170 self.assertTrue(share.feed_isl_discovery(forward))
180 self.assertTrue(share.feed_isl_discovery(reverse))
196 @unittest.skip(
'ISL conflict resolution was disabled, because event topology is responsible for them now')
198 sw_alpha = share.make_datapath_id(1)
199 sw_beta = share.make_datapath_id(2)
200 sw_gamma = share.make_datapath_id(3)
201 sw_delta = share.make_datapath_id(4)
206 isl_beta_alpha = isl_alpha_beta.reversed()
210 isl_gamma_beta = isl_beta_gamma.reversed()
214 isl_delta_gamma = isl_gamma_delta.reversed()
216 for dpid
in sw_alpha, sw_beta, sw_gamma, sw_delta:
219 self.assertTrue(share.feed_isl_discovery(isl_alpha_beta))
220 self.assertTrue(share.feed_isl_discovery(isl_beta_alpha))
221 self.assertTrue(share.feed_isl_discovery(isl_gamma_delta))
222 self.assertTrue(share.feed_isl_discovery(isl_delta_gamma))
225 neo4j_connect, isl_alpha_beta, ISL_STATUS_PROPS_UP)
227 neo4j_connect, isl_beta_alpha, ISL_STATUS_PROPS_UP)
229 neo4j_connect, isl_gamma_delta, ISL_STATUS_PROPS_UP)
231 neo4j_connect, isl_delta_gamma, ISL_STATUS_PROPS_UP)
235 neo4j_connect, isl_beta_gamma)
238 neo4j_connect, isl_gamma_beta)
242 share.feed_isl_discovery(isl_beta_gamma))
245 neo4j_connect, isl_alpha_beta, ISL_STATUS_PROPS_HALF_UP)
247 neo4j_connect, isl_beta_alpha, ISL_STATUS_PROPS_DOWN)
250 neo4j_connect, isl_gamma_delta, ISL_STATUS_PROPS_DOWN)
252 neo4j_connect, isl_delta_gamma, ISL_STATUS_PROPS_HALF_UP)
255 neo4j_connect, isl_beta_gamma, ISL_STATUS_PROPS_HALF_UP)
257 neo4j_connect, isl_gamma_beta, ISL_STATUS_PROPS_DOWN)
260 share.feed_isl_discovery(isl_gamma_beta))
263 neo4j_connect, isl_alpha_beta, ISL_STATUS_PROPS_HALF_UP)
265 neo4j_connect, isl_beta_alpha, ISL_STATUS_PROPS_DOWN)
268 neo4j_connect, isl_gamma_delta, ISL_STATUS_PROPS_DOWN)
270 neo4j_connect, isl_delta_gamma, ISL_STATUS_PROPS_HALF_UP)
273 neo4j_connect, isl_beta_gamma, ISL_STATUS_PROPS_UP)
275 neo4j_connect, isl_gamma_beta, ISL_STATUS_PROPS_UP)
280 reverse = forward.reversed()
284 self.assertTrue(share.feed_isl_discovery(forward))
285 self.assertTrue(share.feed_isl_discovery(reverse))
296 sw_alpha = share.make_datapath_id(1)
297 sw_beta = share.make_datapath_id(2)
301 isl_beta_alpha = isl_alpha_beta.reversed()
308 neo4j_connect, isl_alpha_beta)
311 neo4j_connect, isl_beta_alpha)
314 sw_alpha = share.make_datapath_id(1)
315 sw_beta = share.make_datapath_id(2)
319 isl_beta_alpha = isl_alpha_beta.reversed()
326 neo4j_connect, isl_alpha_beta)
329 neo4j_connect, isl_beta_alpha)
332 sw_alpha = share.make_datapath_id(1)
333 sw_beta = share.make_datapath_id(2)
337 self.assertTrue(share.feed_isl_discovery(isl_alpha_beta))
339 with neo4j_connect.begin()
as tx:
340 isl_utils.set_props(tx, isl_alpha_beta, {
"cost":
"10"})
345 sw_alpha = share.make_datapath_id(1)
346 sw_beta = share.make_datapath_id(2)
347 sw_gamma = share.make_datapath_id(3)
352 isl_beta_alpha = isl_alpha_beta.reversed()
356 isl_gamma_beta = isl_beta_gamma.reversed()
358 for dpid
in sw_alpha, sw_beta, sw_gamma:
361 self.assertTrue(share.feed_isl_discovery(isl_alpha_beta))
362 self.assertTrue(share.feed_isl_discovery(isl_beta_alpha))
363 self.assertTrue(share.feed_isl_discovery(isl_beta_gamma))
364 self.assertTrue(share.feed_isl_discovery(isl_gamma_beta))
368 neo4j_connect, isl_alpha_beta, ISL_STATUS_PROPS_HALF_UP)
370 neo4j_connect, isl_beta_alpha, ISL_STATUS_PROPS_DOWN)
372 neo4j_connect, isl_beta_gamma, ISL_STATUS_PROPS_DOWN)
374 neo4j_connect, isl_gamma_beta, ISL_STATUS_PROPS_HALF_UP)
395 def _cost_raise_on_port_down(self, initial, down, recover):
400 (src_endpoint, initial),
401 (dst_endpoint, initial))
407 (src_endpoint, down),
408 (dst_endpoint, down))
411 share.feed_isl_discovery(isl),
412 'ISL discovery command have failed')
415 (src_endpoint, recover),
416 (dst_endpoint, recover))
418 def _set_isl_cost(self, value):
419 with neo4j_connect.begin()
as tx:
422 isl_utils.set_cost(tx, isl, value)
423 isl_utils.set_cost(tx, isl.reversed(), value)
425 with neo4j_connect.begin()
as tx:
426 props = {
'cost': model.convert_integer(value)}
448 share.feed_isl_discovery(isl),
'ISL discovery command have failed')
463 sw_alpha = share.make_datapath_id(1)
464 sw_beta = share.make_datapath_id(2)
472 self.assertTrue(share.feed_isl_discovery(isl_alpha_beta))
474 with neo4j_connect.begin()
as tx:
475 neo4j_connect.pull(isl_utils.fetch(tx, isl_alpha_beta))
478 {
'time_create':
None,
'time_modify':
None})
480 self.assertTrue(share.feed_isl_discovery(isl_alpha_beta))
483 sw_alpha = share.make_datapath_id(1)
484 sw_beta = share.make_datapath_id(2)
492 update_point_a = model.TimeProperty.now(milliseconds_precission=
True)
494 message = share.command(share.isl_info_payload(isl_alpha_beta))
495 message[
'timestamp'] = update_point_a.as_java_timestamp()
498 recovered = model.TimeProperty.new_from_java_timestamp(message[
'timestamp'])
499 self.assertEquals(update_point_a.value, recovered.value)
501 with neo4j_connect.begin()
as tx:
502 isl = isl_utils.fetch(tx, isl_alpha_beta)
503 neo4j_connect.pull(isl)
505 db_ctime = model.TimeProperty.new_from_db(isl[
'time_create'])
506 self.assertEqual(update_point_a.value, db_ctime.value)
508 db_mtime = model.TimeProperty.new_from_db(isl[
'time_modify'])
509 self.assertEqual(update_point_a.value, db_mtime.value)
512 update_point_b = model.TimeProperty.now(milliseconds_precission=
True)
513 self.assertNotEqual(update_point_a.value, update_point_b.value)
515 message[
'timestamp'] = update_point_b.as_java_timestamp()
517 with neo4j_connect.begin()
as tx:
518 isl = isl_utils.fetch(tx, isl_alpha_beta)
519 neo4j_connect.pull(isl)
521 db_ctime = model.TimeProperty.new_from_db(isl[
'time_create'])
522 self.assertEqual(update_point_a.value, db_ctime.value)
524 db_mtime = model.TimeProperty.new_from_db(isl[
'time_modify'])
525 self.assertEqual(update_point_b.value, db_mtime.value)
528 isl_record = isl_utils.fetch(tx, isl)
529 neo4j_connect.pull(isl_record)
532 props[name], isl_record[name],
533 "Invalid ISL's {!r} value ({!r})".
format(name, isl_record))
538 for pair
in endpoint_cost_pairs:
539 endpoints.append(pair[0])
540 costs.append(pair[1])
542 for isl, expect
in zip(self.
enumerate_isl(*endpoints), costs):
545 'Bad "cost" value {!r} (expect {!r}) in isl {!r}'.
format(
546 isl[
'cost'], expect, isl))
549 with neo4j_connect.begin()
as tx:
550 for node
in endpoints:
552 'MATCH (a:switch)-[self:isl]->(:switch)\n' 553 'WHERE a.name=$dpid\n' 556 for data_set
in tx.run(q, dpid=node.dpid):
557 node = data_set[
'self']
558 neo4j_connect.pull(node)
568 with neo4j_connect.begin()
as tx:
569 payload = {
'cost': 10}
def ensure_isl_costs(self, endpoint_cost_pairs)
def test_isl_down_without_isl(self)
def test_port_down_with_cost_as_string(self)
def test_isl_status(self)
def test_moved_isl_should_be_marked(self)
def _set_isl_cost(self, value)
def make_isl_pair(source, dest)
def _cost_raise_on_port_down(self, initial, down, recover)
def test_multi_isl_port_down(self)
def feed_service(self, message, can_fail=False)
def test_no_cost_raise_on_isl_down(self)
def enumerate_isl(self, endpoints)
def test_isl_without_life_cycle_fields(self)
def setup_initial_data(self, make_link_props=True)
def make_switch_add(dpid)
def ensure_isl_props(self, tx, isl, props)
def test_switch_unplug(self)
def make_isl_failed(source)
def make_port_down(endpoint)
def inject_db_link_props(tx, source, dest, payload)
def test_isl_replug(self)
def test_cost_raise_on_port_down(self)
def test_port_down_without_isl(self)
def test_time_update_on_isl_discovery(self)
def test_cost_raise_on_port_down_without_link_props(self)
def make_switch_remove(dpid)