use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Rib 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Rib in project bgpcep by opendaylight.
the class AddPathAbstractRouteEntry method fillAdjRibsOut.
@SuppressWarnings("unchecked")
private void fillAdjRibsOut(final boolean isFirstBestPath, final Attributes attributes, final Route routeNonAddPath, final Route routeAddPath, final Identifier routeKeyAddNonPath, final Identifier routeKeyAddPath, final PeerId fromPeerId, final TablesKey localTK, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
/*
* We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
* expose from which client a particular route was learned from in the local RIB, and have
* the listener perform filtering.
*
* We walk the policy set in order to minimize the amount of work we do for multiple peers:
* if we have two eBGP peers, for example, there is no reason why we should perform the translation
* multiple times.
*/
final RIBSupport ribSupport = routeEntryDep.getRibSupport();
for (final Peer toPeer : this.peerTracker.getPeers()) {
if (!filterRoutes(fromPeerId, toPeer, localTK)) {
continue;
}
final boolean destPeerSupAddPath = toPeer.supportsAddPathSupported(localTK);
if (toPeer.getPeerId().getValue().equals("bgp://127.0.0.5")) {
LOG.debug("Write route {} to peer AdjRibsOut {}", toPeer.getPeerId());
}
if (peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath)) {
Optional<Attributes> effAttrib = Optional.empty();
final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
if (fromPeer != null && attributes != null) {
final BGPRouteEntryExportParameters baseExp = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
effAttrib = routeEntryDep.getRoutingPolicies().applyExportPolicies(baseExp, attributes);
}
Route newRoute = null;
InstanceIdentifier ribOutRoute = null;
if (destPeerSupAddPath) {
newRoute = routeAddPath;
ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddPath);
} else if (!this.oldNonAddPathBestPathTheSame) {
ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddNonPath);
newRoute = routeNonAddPath;
}
if (effAttrib.isPresent() && newRoute != null) {
LOG.debug("Write route {} to peer AdjRibsOut {}", newRoute, toPeer.getPeerId());
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute, newRoute);
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute.child(Attributes.class), effAttrib.get());
} else if (ribOutRoute != null) {
LOG.trace("Removing {} from transaction for peer {}", ribOutRoute, toPeer.getPeerId());
tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutRoute);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Rib in project bgpcep by opendaylight.
the class BGPOperationalStateUtils method readGlobalFromDataStore.
private static Bgp readGlobalFromDataStore(final DataBroker dataBroker, final String ribId) {
final InstanceIdentifier<Bgp> bgpIID = PROTOCOLS_IID.child(Protocol.class, new ProtocolKey(BGP.class, ribId)).augmentation(NetworkInstanceProtocol.class).child(Bgp.class);
final ReadTransaction rot = dataBroker.newReadOnlyTransaction();
try {
return rot.read(LogicalDatastoreType.OPERATIONAL, bgpIID).get().orElse(null);
} catch (final InterruptedException | ExecutionException e) {
LOG.warn("Failed to read rib {}", ribId, e);
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Rib in project bgpcep by opendaylight.
the class ParserTest method testEORLS.
/*
* End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 1d <- length (29) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 06 <- total path attribute length
* 80 <- attribute flags
* 0f <- attribute type (15 - MP_UNREACH_NLRI)
* 03 <- attribute length
* 40 04 <- value (AFI 16388: LS)
* 47 <- value (SAFI 71)
*/
@Test
public void testEORLS() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(0), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
final Class<? extends AddressFamily> afi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getAfi();
final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getSafi();
assertEquals(LinkstateAddressFamily.class, afi);
assertEquals(LinkstateSubsequentAddressFamily.class, safi);
final ByteBuf buffer = Unpooled.buffer();
ParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(INPUT_BYTES.get(0), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Rib in project bgpcep by opendaylight.
the class StateProviderImplTest method setUp.
@Before
public void setUp() {
doReturn(IPV4UNICAST.class).when(this.tableTypeRegistry).getAfiSafiType(eq(TABLES_KEY));
doReturn(this.bgpRibStates).when(this.stateProvider).getRibStats();
doReturn(this.bgpPeerStates).when(this.stateProvider).getPeerStats();
final KeyedInstanceIdentifier<Rib, RibKey> iid = InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(new RibId(this.ribId)));
doReturn(iid).when(this.bgpRibState).getInstanceIdentifier();
doReturn(this.as).when(this.bgpRibState).getAs();
doReturn(this.bgpId).when(this.bgpRibState).getRouteId();
doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpRibState).getTotalPathsCount();
doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpRibState).getTotalPrefixesCount();
doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpRibState).getPathCount(eq(TABLES_KEY));
doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpRibState).getPrefixesCount(eq(TABLES_KEY));
doAnswer(invocation -> Map.of(TABLES_KEY, this.totalPathsCounter.longValue())).when(this.bgpRibState).getPathsCount();
// Mock Peer
doReturn("test-group").when(this.bgpPeerState).getGroupId();
doReturn(iid).when(this.bgpPeerState).getInstanceIdentifier();
doAnswer(invocation -> this.totalPrefixesCounter.longValue()).when(this.bgpPeerState).getTotalPrefixes();
doAnswer(invocation -> this.totalPathsCounter.longValue()).when(this.bgpPeerState).getTotalPathsCount();
doReturn(this.neighborAddress).when(this.bgpPeerState).getNeighborAddress();
doReturn(this.bgpSessionState).when(this.bgpPeerState).getBGPSessionState();
doReturn(this.bgpPeerMessagesState).when(this.bgpPeerState).getBGPPeerMessagesState();
doReturn(1L).when(this.bgpPeerMessagesState).getNotificationMessagesReceivedCount();
doReturn(1L).when(this.bgpPeerMessagesState).getNotificationMessagesSentCount();
doReturn(1L).when(this.bgpPeerMessagesState).getUpdateMessagesReceivedCount();
doReturn(1L).when(this.bgpPeerMessagesState).getUpdateMessagesSentCount();
doReturn(State.UP).when(this.bgpSessionState).getSessionState();
doReturn(true).when(this.bgpSessionState).isAddPathCapabilitySupported();
doReturn(true).when(this.bgpSessionState).isAsn32CapabilitySupported();
doReturn(true).when(this.bgpSessionState).isGracefulRestartCapabilitySupported();
doReturn(true).when(this.bgpSessionState).isMultiProtocolCapabilitySupported();
doReturn(true).when(this.bgpSessionState).isRouterRefreshCapabilitySupported();
doReturn(this.timersState).when(this.bgpPeerState).getBGPTimersState();
doReturn(10L).when(this.timersState).getNegotiatedHoldTime();
doReturn(10L).when(this.timersState).getUpTime();
doReturn(this.bgpTransportState).when(this.bgpPeerState).getBGPTransportState();
doReturn(this.localPort).when(this.bgpTransportState).getLocalPort();
doReturn(this.neighborAddress).when(this.bgpTransportState).getRemoteAddress();
doReturn(this.remotePort).when(this.bgpTransportState).getRemotePort();
doReturn(this.bgpErrorHandlingState).when(this.bgpPeerState).getBGPErrorHandlingState();
doReturn(1L).when(this.bgpErrorHandlingState).getErroneousUpdateReceivedCount();
doReturn(this.bgpGracelfulRestartState).when(this.bgpPeerState).getBGPGracelfulRestart();
doReturn(true).when(this.bgpGracelfulRestartState).isLocalRestarting();
doReturn(true).when(this.bgpGracelfulRestartState).isPeerRestarting();
doReturn(this.restartTime.toJava()).when(this.bgpGracelfulRestartState).getPeerRestartTime();
doReturn(BgpAfiSafiGracefulRestartState.Mode.BILATERAL).when(this.bgpGracelfulRestartState).getMode();
doReturn(this.bgpAfiSafiState).when(this.bgpPeerState).getBGPAfiSafiState();
doReturn(Set.of(TABLES_KEY)).when(this.bgpAfiSafiState).getAfiSafisAdvertized();
doReturn(Set.of(TABLES_KEY)).when(this.bgpAfiSafiState).getAfiSafisReceived();
doReturn(1L).when(this.bgpAfiSafiState).getPrefixesInstalledCount(any());
doReturn(2L).when(this.bgpAfiSafiState).getPrefixesReceivedCount(any());
doReturn(1L).when(this.bgpAfiSafiState).getPrefixesSentCount(any());
doReturn(true).when(this.bgpAfiSafiState).isAfiSafiSupported(any());
doReturn(true).when(this.bgpAfiSafiState).isGracefulRestartAdvertized(any());
doReturn(true).when(this.bgpAfiSafiState).isGracefulRestartReceived(any());
doReturn(true).when(this.bgpAfiSafiState).isLlGracefulRestartAdvertised(any());
doReturn(true).when(this.bgpAfiSafiState).isLlGracefulRestartReceived(any());
doReturn(60).when(this.bgpAfiSafiState).getLlGracefulRestartTimer(any());
}
Aggregations