use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.Peer in project bgpcep by opendaylight.
the class BgpPeerTest method testBgpPeer.
@Test
public void testBgpPeer() {
final Neighbor neighbor = new NeighborBuilder().setAfiSafis(createAfiSafi()).setConfig(createConfig()).setNeighborAddress(NEIGHBOR_ADDRESS).setRouteReflector(createRR()).setTimers(createTimers()).setTransport(createTransport()).setAddPaths(createAddPath()).build();
this.bgpPeer.start(this.rib, neighbor, null, this.peerGroupLoader, this.tableTypeRegistry);
Mockito.verify(this.rib).createPeerDOMChain(any());
Mockito.verify(this.rib, times(2)).getLocalAs();
Mockito.verify(this.rib).getLocalTables();
this.bgpPeer.instantiateServiceInstance();
Mockito.verify(this.bgpPeerRegistry).addPeer(any(), any(), any());
Mockito.verify(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class), anyInt(), any(KeyMapping.class));
try {
this.bgpPeer.start(this.rib, neighbor, null, this.peerGroupLoader, this.tableTypeRegistry);
fail("Expected Exception");
} catch (final IllegalStateException expected) {
assertEquals("Previous peer instance was not closed.", expected.getMessage());
}
this.bgpPeer.setServiceRegistration(this.serviceRegistration);
this.bgpPeer.closeServiceInstance();
this.bgpPeer.close();
Mockito.verify(this.future).cancel(true);
this.bgpPeer.restart(this.rib, null, this.peerGroupLoader, this.tableTypeRegistry);
this.bgpPeer.instantiateServiceInstance();
Mockito.verify(this.rib, times(2)).createPeerDOMChain(any());
Mockito.verify(this.rib, times(4)).getLocalAs();
Mockito.verify(this.rib, times(2)).getLocalTables();
final Neighbor neighborExpected = createNeighborExpected(NEIGHBOR_ADDRESS);
assertTrue(this.bgpPeer.containsEqualConfiguration(neighborExpected));
assertFalse(this.bgpPeer.containsEqualConfiguration(createNeighborExpected(new IpAddress(new Ipv4Address("127.0.0.2")))));
Mockito.verify(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
this.bgpPeer.closeServiceInstance();
this.bgpPeer.close();
Mockito.verify(this.serviceRegistration).unregister();
Mockito.verify(this.future, times(2)).cancel(true);
final Neighbor neighborDiffConfig = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS).setAfiSafis(createAfiSafi()).build();
this.bgpPeer.start(this.rib, neighborDiffConfig, null, this.peerGroupLoader, this.tableTypeRegistry);
assertTrue(this.bgpPeer.containsEqualConfiguration(neighborDiffConfig));
this.bgpPeer.close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.Peer in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testDuplicatePeersLowerAs.
@Test
public void testDuplicatePeersLowerAs() throws Exception {
final AsNumber as2 = new AsNumber(3L);
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
try {
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
}
fail("Same peer cannot be connected twice");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.Peer in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testAsMismatch.
@Test
public void testAsMismatch() throws Exception {
final AsNumber as2 = new AsNumber(3L);
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
try {
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.BAD_PEER_AS, e.getError());
return;
}
fail("Peer AS number mismatch");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.Peer in project bgpcep by opendaylight.
the class BGPPeer method onSessionUp.
@Override
public synchronized void onSessionUp(final BGPSession session) {
this.session = session;
if (this.session instanceof BGPSessionStateProvider) {
((BGPSessionStateProvider) this.session).registerMessagesCounter(this);
}
final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
final List<BgpTableType> advertizedGracefulRestartTableTypes = session.getAdvertisedGracefulRestartTableTypes();
LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", this.name, advertizedTableTypes, addPathTablesType);
this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
final Set<TablesKey> setTables = advertizedTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toSet());
this.tables = ImmutableSet.copyOf(setTables);
setAdvertizedGracefulRestartTableTypes(advertizedGracefulRestartTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
this.addPathTableMaps = ImmutableMap.copyOf(mapTableTypesFamilies(addPathTablesType));
this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
for (final TablesKey key : this.tables) {
createAdjRibOutListener(key, true);
}
addBgp4Support();
this.effRibInWriter = EffectiveRibInWriter.create(this, this.rib, this.rib.createPeerChain(this), this.peerIId, this.tables);
registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
this.ribWriter = this.ribWriter.transform(this.peerId, this.rib.getRibSupportContext(), this.tables, this.addPathTableMaps);
if (this.rpcRegistry != null) {
this.rpcRegistration = this.rpcRegistry.addRoutedRpcImplementation(BgpPeerRpcService.class, new BgpPeerRpc(this, session, this.tables));
final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer, PeerKey> path = this.rib.getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer.class, new PeerKey(this.peerId));
this.rpcRegistration.registerPath(PeerContext.class, path);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.Peer in project bgpcep by opendaylight.
the class LocRibWriter method update.
@SuppressWarnings("unchecked")
private Map<RouteUpdateKey, RouteEntry> update(final WriteTransaction tx, final Collection<DataTreeModification<Tables>> changes) {
final Map<RouteUpdateKey, RouteEntry> ret = new HashMap<>();
for (final DataTreeModification<Tables> tc : changes) {
final DataObjectModification<Tables> table = tc.getRootNode();
final DataTreeIdentifier<Tables> rootPath = tc.getRootPath();
final KeyedInstanceIdentifier<Peer, PeerKey> peerKIid = (KeyedInstanceIdentifier<Peer, PeerKey>) rootPath.getRootIdentifier().firstIdentifierOf(Peer.class);
final UnsignedInteger peerUuid = RouterIds.routerIdForPeerId(peerKIid.getKey().getPeerId());
/*
Initialize Peer with routes under loc rib
*/
if (!this.routeEntries.isEmpty() && table.getDataBefore() == null) {
final org.opendaylight.protocol.bgp.rib.spi.Peer peer = this.peerTracker.getPeer(peerKIid.getKey().getPeerId());
if (peer != null && peer.supportsTable(this.entryDep.getLocalTablesKey())) {
LOG.debug("Peer {} table has been created, inserting existent routes", peer.getPeerId());
this.routeEntries.forEach((key, value) -> value.initializeBestPaths(this.entryDep, new RouteEntryInfoImpl(peer, key), tx));
}
}
/*
Process new routes from Peer
*/
updateNodes(table, peerUuid, tx, ret);
}
return ret;
}
Aggregations