use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.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 ReadOnlyTransaction rot = dataBroker.newReadOnlyTransaction();
try {
return rot.read(LogicalDatastoreType.OPERATIONAL, bgpIID).get().orNull();
} 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.rev171207.Rib in project bgpcep by opendaylight.
the class BGPParserTest method testEORIpv6.
/*
* End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
*
* 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
* 00 02 <- value (AFI 2: IPv6)
* 01 <- value (SAFI 1)
*/
@Test
public void testEORIpv6() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
assertEquals(Ipv6AddressFamily.class, afi);
assertEquals(UnicastSubsequentAddressFamily.class, safi);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Rib in project bgpcep by opendaylight.
the class BGPParserTest method testEORIpv4.
/*
* End of Rib for Ipv4.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 17 <- length (23) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 00 <- total path attribute length
*/
@Test
public void testEORIpv4() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
assertEquals(new UpdateBuilder().build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(inputBytes.get(5), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Rib in project bgpcep by opendaylight.
the class StateProviderImplTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
doReturn(Optional.of(IPV4UNICAST.class)).when(this.tableTypeRegistry).getAfiSafiType(eq(TABLES_KEY));
doReturn(this.bgpRibStates).when(this.stateCollector).getRibStats();
doReturn(this.bgpPeerStates).when(this.stateCollector).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 -> Collections.singletonMap(TABLES_KEY, this.totalPrefixesCounter.longValue())).when(this.bgpRibState).getTablesPrefixesCount();
doAnswer(invocation -> Collections.singletonMap(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(1L).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).isGracefulRestartAdvertized(any());
doReturn(true).when(this.bgpGracelfulRestartState).isGracefulRestartReceived(any());
doReturn(true).when(this.bgpGracelfulRestartState).isLocalRestarting();
doReturn(true).when(this.bgpGracelfulRestartState).isPeerRestarting();
doReturn(this.restartTime).when(this.bgpGracelfulRestartState).getPeerRestartTime();
doReturn(this.bgpAfiSafiState).when(this.bgpPeerState).getBGPAfiSafiState();
doReturn(Collections.singleton(TABLES_KEY)).when(this.bgpAfiSafiState).getAfiSafisAdvertized();
doReturn(Collections.singleton(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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.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);
}
}
}
}
Aggregations