def test_read(self):
     concrete_anns = self.get_anns()
     ctx = SolverContext.create_context(concrete_anns)
     sym_anns = read_announcements(concrete_anns, ctx)
     self.assertEqual(len(sym_anns), len(concrete_anns))
     for sym_ann, con_ann in zip(sym_anns, concrete_anns):
         for attr in Announcement.attributes:
             if attr == 'communities':
                 for community in con_ann.communities:
                     con_val = con_ann.communities[community]
                     sym_val = sym_ann.communities[community]
                     if is_empty(con_val):
                         self.assertFalse(sym_val.is_concrete)
                     else:
                         self.assertTrue(sym_val.is_concrete)
                         self.assertEquals(sym_val.get_value(), con_val)
                 continue
             con_val = getattr(con_ann, attr)
             sym_val = getattr(sym_ann, attr)
             if is_empty(con_val):
                 self.assertFalse(sym_val.is_concrete)
             else:
                 self.assertTrue(sym_val.is_concrete)
                 if attr == 'as_path':
                     con_val = get_as_path_key(con_val)
                 sym_val_concrete = sym_val.get_value()
                 if attr == 'origin':
                     sym_val_concrete = BGP_ATTRS_ORIGIN.__members__[
                         sym_val_concrete]
                 self.assertEquals(sym_val_concrete, con_val)
 def test_create(self):
     # Arrange
     concrete_anns = self.get_anns()
     ctx = SolverContext.create_context(concrete_anns)
     # Act
     sym_anns = read_announcements(concrete_anns, ctx)
     # Assert
     self.assertEquals(len(sym_anns), 2)
Beispiel #3
0
def create_context(reqs, g, announcements, create_as_paths=False):
    connected = ConnectedSyn([], g, full=True)
    connected.synthesize()
    next_hops_map = compute_next_hop_map(g)
    next_hops = extract_all_next_hops(next_hops_map)
    peers = [node for node in g.routers_iter() if g.is_bgp_enabled(node)]
    ctx = SolverContext.create_context(announcements,
                                       peer_list=peers,
                                       next_hop_list=next_hops,
                                       create_as_paths=create_as_paths)
    return ctx
 def test_sub(self):
     # Arrange
     concrete_anns = self.get_anns()
     ctx = SolverContext.create_context(concrete_anns)
     sym_anns = read_announcements(concrete_anns, ctx)
     mutator = self
     # Act
     new_anns = sym_anns.create_new([sym_anns[0]], mutator)
     new_anns2 = new_anns.create_new([new_anns[0]], mutator)
     self.assertEquals(len(sym_anns), 2)
     self.assertEquals(len(new_anns), 1)
     self.assertEquals(len(new_anns2), 1)
     self.assertEquals(sym_anns.mutators, [])
     self.assertEquals(new_anns.mutators, [mutator])
     self.assertEquals(new_anns2.mutators, [mutator, mutator])
 def create_context(self, reqs, g):
     connected = ConnectedSyn(reqs, g, full=True)
     connected.synthesize()
     next_hops_map = compute_next_hop_map(g)
     next_hops = extract_all_next_hops(next_hops_map)
     peers = [node for node in g.routers_iter() if g.is_bgp_enabled(node)]
     anns = self.get_anns()
     for ann in anns:
         g.add_bgp_advertise(node=ann.peer,
                             announcement=ann,
                             loopback='lo0')
     ctx = SolverContext.create_context(anns,
                                        next_hop_list=next_hops,
                                        peer_list=peers,
                                        create_as_paths=False)
     return ctx
Beispiel #6
0
 def _create_context(self, create_as_paths=False):
     """
     Create the context to hold symbolic variables used in BGP synthesis
     :param create_as_paths:
     :return: SolverContext
     """
     next_hops_map = compute_next_hop_map(self.topo)
     next_hops = extract_all_next_hops(next_hops_map)
     peers = [
         node for node in self.topo.routers_iter()
         if self.topo.is_bgp_enabled(node)
     ]
     print "PEER", peers
     print "NEXTHOPS", next_hops
     ctx = SolverContext.create_context(self.announcements,
                                        peer_list=peers,
                                        next_hop_list=next_hops,
                                        create_as_paths=create_as_paths)
     return ctx