use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project bgpcep by opendaylight.
the class BmpMonitorImplTest method testMonitoringStation.
private Channel testMonitoringStation(final String remoteRouterIpAddr) throws InterruptedException, ExecutionException {
final Channel channel = connectTestClient(remoteRouterIpAddr, msgRegistry);
final RouterId routerId = getRouterId(remoteRouterIpAddr);
readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
// now find the current router instance
Router router = null;
for (final Router r : monitor.nonnullRouter().values()) {
if (routerId.equals(r.getRouterId())) {
router = r;
break;
}
}
assertNotNull(router);
assertEquals(Status.Down, router.getStatus());
assertNull(router.getPeer());
return router;
});
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createInitMsg("description", "name", "some info")));
readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
Router retRouter = null;
for (final Router r : monitor.nonnullRouter().values()) {
if (routerId.equals(r.getRouterId())) {
retRouter = r;
break;
}
}
assertNotNull(retRouter);
assertEquals("some info;", retRouter.getInfo());
assertEquals("name", retRouter.getName());
assertEquals("description", retRouter.getDescription());
assertEquals(routerId, retRouter.getRouterId());
assertNull(retRouter.getPeer());
assertEquals(Status.Up, retRouter.getStatus());
return retRouter;
});
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createPeerUpNotification(PEER1, true)));
final KeyedInstanceIdentifier<Router, RouterKey> routerIId = MONITOR_IID.child(Router.class, new RouterKey(routerId));
readDataOperational(getDataBroker(), routerIId, router -> {
final Map<PeerKey, Peer> peers = router.getPeer();
assertNotNull(peers);
assertEquals(1, peers.size());
final Peer peer = peers.values().iterator().next();
assertEquals(PeerType.Global, peer.getType());
assertEquals(PEER_ID, peer.getPeerId());
assertEquals(PEER1, peer.getBgpId());
assertEquals(TestUtil.IPV4_ADDRESS_10, peer.getAddress().getIpv4AddressNoZone());
assertEquals(TestUtil.PEER_AS, peer.getAs());
assertNull(peer.getPeerDistinguisher());
assertNull(peer.getStats());
assertNotNull(peer.getPrePolicyRib());
assertEquals(1, peer.getPrePolicyRib().nonnullTables().size());
final Tables prePolicyTable = peer.getPrePolicyRib().nonnullTables().values().iterator().next();
assertEquals(Ipv4AddressFamily.class, prePolicyTable.getAfi());
assertEquals(UnicastSubsequentAddressFamily.class, prePolicyTable.getSafi());
assertFalse(prePolicyTable.getAttributes().getUptodate());
assertNotNull(peer.getPostPolicyRib());
assertEquals(1, peer.getPostPolicyRib().nonnullTables().size());
final Tables postPolicyTable = peer.getPrePolicyRib().nonnullTables().values().iterator().next();
assertEquals(Ipv4AddressFamily.class, postPolicyTable.getAfi());
assertEquals(UnicastSubsequentAddressFamily.class, postPolicyTable.getSafi());
assertFalse(postPolicyTable.getAttributes().getUptodate());
assertNotNull(peer.getPeerSession());
final PeerSession peerSession = peer.getPeerSession();
assertEquals(TestUtil.IPV4_ADDRESS_10, peerSession.getLocalAddress().getIpv4AddressNoZone());
assertEquals(TestUtil.PEER_LOCAL_PORT, peerSession.getLocalPort());
assertEquals(TestUtil.PEER_REMOTE_PORT, peerSession.getRemotePort());
assertEquals(Status.Up, peerSession.getStatus());
assertNotNull(peerSession.getReceivedOpen());
assertNotNull(peerSession.getSentOpen());
return router;
});
final StatsReportsMessage statsMsg = TestUtil.createStatsReportMsg(PEER1);
waitWriteAndFlushSuccess(channel.writeAndFlush(statsMsg));
final KeyedInstanceIdentifier<Peer, PeerKey> peerIId = routerIId.child(Peer.class, new PeerKey(PEER_ID));
readDataOperational(getDataBroker(), peerIId.child(Stats.class), peerStats -> {
assertNotNull(peerStats.getTimestampSec());
final Tlvs tlvs = statsMsg.getTlvs();
assertEquals(tlvs.getAdjRibsInRoutesTlv().getCount(), peerStats.getAdjRibsInRoutes());
assertEquals(tlvs.getDuplicatePrefixAdvertisementsTlv().getCount(), peerStats.getDuplicatePrefixAdvertisements());
assertEquals(tlvs.getDuplicateWithdrawsTlv().getCount(), peerStats.getDuplicateWithdraws());
assertEquals(tlvs.getInvalidatedAsConfedLoopTlv().getCount(), peerStats.getInvalidatedAsConfedLoop());
assertEquals(tlvs.getInvalidatedAsPathLoopTlv().getCount(), peerStats.getInvalidatedAsPathLoop());
assertEquals(tlvs.getInvalidatedClusterListLoopTlv().getCount(), peerStats.getInvalidatedClusterListLoop());
assertEquals(tlvs.getInvalidatedOriginatorIdTlv().getCount(), peerStats.getInvalidatedOriginatorId());
assertEquals(tlvs.getLocRibRoutesTlv().getCount(), peerStats.getLocRibRoutes());
assertEquals(tlvs.getRejectedPrefixesTlv().getCount(), peerStats.getRejectedPrefixes());
assertEquals(tlvs.getPerAfiSafiAdjRibInTlv().getCount().toString(), peerStats.getPerAfiSafiAdjRibInRoutes().nonnullAfiSafi().values().iterator().next().getCount().toString());
assertEquals(tlvs.getPerAfiSafiLocRibTlv().getCount().toString(), peerStats.getPerAfiSafiLocRibRoutes().nonnullAfiSafi().values().iterator().next().getCount().toString());
return peerStats;
});
// route mirror message test
final RouteMirroringMessage routeMirrorMsg = TestUtil.createRouteMirrorMsg(PEER1);
waitWriteAndFlushSuccess(channel.writeAndFlush(routeMirrorMsg));
readDataOperational(getDataBroker(), peerIId.child(Mirrors.class), routeMirrors -> {
assertNotNull(routeMirrors.getTimestampSec());
return routeMirrors;
});
waitWriteAndFlushSuccess(channel.writeAndFlush(createRouteMonitMsg(false, PEER1, AdjRibInType.PrePolicy)));
waitWriteAndFlushSuccess(channel.writeAndFlush(createRouteMonMsgWithEndOfRibMarker(PEER1, AdjRibInType.PrePolicy)));
readDataOperational(getDataBroker(), peerIId.child(PrePolicyRib.class), prePolicyRib -> {
assertFalse(prePolicyRib.nonnullTables().isEmpty());
final Tables tables = prePolicyRib.nonnullTables().values().iterator().next();
assertTrue(tables.getAttributes().getUptodate());
assertEquals(3, ((Ipv4RoutesCase) tables.getRoutes()).getIpv4Routes().nonnullIpv4Route().size());
return tables;
});
waitWriteAndFlushSuccess(channel.writeAndFlush(createRouteMonitMsg(false, PEER1, AdjRibInType.PostPolicy)));
waitWriteAndFlushSuccess(channel.writeAndFlush(createRouteMonMsgWithEndOfRibMarker(PEER1, AdjRibInType.PostPolicy)));
readDataOperational(getDataBroker(), peerIId.child(PostPolicyRib.class), postPolicyRib -> {
assertFalse(postPolicyRib.nonnullTables().isEmpty());
final Tables tables = postPolicyRib.nonnullTables().values().iterator().next();
assertTrue(tables.getAttributes().getUptodate());
assertEquals(3, ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bmp.monitor.monitor.router.peer.post.policy.rib.tables.routes.Ipv4RoutesCase) tables.getRoutes()).getIpv4Routes().nonnullIpv4Route().size());
return tables;
});
waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createPeerDownNotification(PEER1)));
readDataOperational(getDataBroker(), routerIId, router -> {
assertNull(router.getPeer());
return router;
});
return channel;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project bgpcep by opendaylight.
the class BmpMonitorImplTest method deploySecondInstance.
@Test
public void deploySecondInstance() throws Exception {
final BmpMonitoringStation monitoringStation2 = new BmpMonitoringStationImpl(getDomBroker(), dispatcher, ribExtension, mappingService.currentSerializer(), clusterSSProv2, new MonitorId("monitor2"), new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS_2), MONITOR_LOCAL_PORT), null);
readDataOperational(getDataBroker(), BMP_II, monitor -> {
assertEquals(2, monitor.nonnullMonitor().size());
return monitor;
});
monitoringStation2.close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project bgpcep by opendaylight.
the class BmpMonitorImplTest method setUp.
@Before
public void setUp() throws Exception {
super.setup();
doAnswer(invocationOnMock -> {
BmpMonitorImplTest.this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
singletonService.instantiateServiceInstance();
return BmpMonitorImplTest.this.singletonServiceRegistration;
}).when(clusterSSProv).registerClusterSingletonService(any(ClusterSingletonService.class));
doAnswer(invocationOnMock -> BmpMonitorImplTest.this.singletonService.closeServiceInstance()).when(singletonServiceRegistration).close();
doAnswer(invocationOnMock -> {
singletonService2 = (ClusterSingletonService) invocationOnMock.getArguments()[0];
singletonService2.instantiateServiceInstance();
return BmpMonitorImplTest.this.singletonServiceRegistration2;
}).when(clusterSSProv2).registerClusterSingletonService(any(ClusterSingletonService.class));
doAnswer(invocationOnMock -> BmpMonitorImplTest.this.singletonService2.closeServiceInstance()).when(singletonServiceRegistration2).close();
ribActivator.startRIBExtensionProvider(ribExtension, mappingService.currentSerializer());
final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
bgpActivator.start(context);
final SimpleBmpExtensionProviderContext ctx = new SimpleBmpExtensionProviderContext();
bmpActivator = new BmpActivator(context);
bmpActivator.start(ctx);
msgRegistry = ctx.getBmpMessageRegistry();
dispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx, new DefaultBmpSessionFactory());
final InetSocketAddress inetAddress = new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS), MONITOR_LOCAL_PORT);
final DOMDataTreeWriteTransaction wTx = getDomBroker().newWriteOnlyTransaction();
final ContainerNode parentNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BmpMonitor.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Monitor.QNAME).build()).build();
wTx.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.of(BmpMonitor.QNAME), parentNode);
wTx.commit().get();
bmpApp = new BmpMonitoringStationImpl(getDomBroker(), dispatcher, ribExtension, mappingService.currentSerializer(), clusterSSProv, MONITOR_ID, inetAddress, null);
readDataOperational(getDataBroker(), BMP_II, monitor -> {
assertEquals(1, monitor.nonnullMonitor().size());
final Monitor bmpMonitor = monitor.nonnullMonitor().values().iterator().next();
assertEquals(MONITOR_ID, bmpMonitor.getMonitorId());
assertEquals(0, bmpMonitor.nonnullRouter().size());
assertEquals(MONITOR_ID, bmpMonitor.getMonitorId());
assertEquals(0, bmpMonitor.nonnullRouter().size());
return monitor;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.bmp.monitor.Monitor in project bgpcep by opendaylight.
the class BmpMonitoringStationImpl method closeServiceInstance.
@Override
public synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
LOG.info("BMP Monitor Singleton Service {} instance closed, Monitor Id {}", getIdentifier().getName(), monitorId.getValue());
if (channel != null) {
channel.close().addListener((ChannelFutureListener) future -> {
Preconditions.checkArgument(future.isSuccess(), "Channel failed to close: %s", future.cause());
BmpMonitoringStationImpl.this.sessionManager.close();
});
}
final DOMDataTreeWriteTransaction wTx = domDataBroker.newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.OPERATIONAL, yangMonitorId);
LOG.info("BMP monitoring station {} closed.", monitorId.getValue());
return wTx.commit();
}
Aggregations