Search in sources :

Example 81 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project bgpcep by opendaylight.

the class BmpMonitorImplTest method testMonitoringStation.

private Channel testMonitoringStation(final String remoteRouterIpAddr) throws InterruptedException, ReadFailedException {
    final Channel channel = connectTestClient(remoteRouterIpAddr, this.msgRegistry);
    final RouterId routerId = getRouterId(remoteRouterIpAddr);
    readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
        assertFalse(monitor.getRouter().isEmpty());
        // now find the current router instance
        Router router = null;
        for (final Router r : monitor.getRouter()) {
            if (routerId.equals(r.getRouterId())) {
                router = r;
                break;
            }
        }
        assertNotNull(router);
        assertEquals(Status.Down, router.getStatus());
        assertTrue(router.getPeer().isEmpty());
        return router;
    });
    waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createInitMsg("description", "name", "some info")));
    readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
        assertFalse(monitor.getRouter().isEmpty());
        Router retRouter = null;
        for (final Router r : monitor.getRouter()) {
            if (routerId.equals(r.getRouterId())) {
                retRouter = r;
                break;
            }
        }
        assertEquals("some info;", retRouter.getInfo());
        assertEquals("name", retRouter.getName());
        assertEquals("description", retRouter.getDescription());
        assertEquals(routerId, retRouter.getRouterId());
        assertTrue(retRouter.getPeer().isEmpty());
        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 List<Peer> peers = router.getPeer();
        assertEquals(1, peers.size());
        final Peer peer = peers.get(0);
        assertEquals(PeerType.Global, peer.getType());
        assertEquals(PEER_ID, peer.getPeerId());
        assertEquals(PEER1, peer.getBgpId());
        assertEquals(TestUtil.IPV4_ADDRESS_10, peer.getAddress().getIpv4Address());
        assertEquals(TestUtil.PEER_AS, peer.getAs());
        assertNull(peer.getPeerDistinguisher());
        assertNull(peer.getStats());
        assertNotNull(peer.getPrePolicyRib());
        assertEquals(1, peer.getPrePolicyRib().getTables().size());
        final Tables prePolicyTable = peer.getPrePolicyRib().getTables().get(0);
        assertEquals(Ipv4AddressFamily.class, prePolicyTable.getAfi());
        assertEquals(UnicastSubsequentAddressFamily.class, prePolicyTable.getSafi());
        assertFalse(prePolicyTable.getAttributes().isUptodate());
        assertNotNull(prePolicyTable.getRoutes());
        assertNotNull(peer.getPostPolicyRib());
        assertEquals(1, peer.getPostPolicyRib().getTables().size());
        final Tables postPolicyTable = peer.getPrePolicyRib().getTables().get(0);
        assertEquals(Ipv4AddressFamily.class, postPolicyTable.getAfi());
        assertEquals(UnicastSubsequentAddressFamily.class, postPolicyTable.getSafi());
        assertFalse(postPolicyTable.getAttributes().isUptodate());
        assertNotNull(postPolicyTable.getRoutes());
        assertNotNull(peer.getPeerSession());
        final PeerSession peerSession = peer.getPeerSession();
        assertEquals(TestUtil.IPV4_ADDRESS_10, peerSession.getLocalAddress().getIpv4Address());
        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().getAfiSafi().get(0).getCount().toString());
        assertEquals(tlvs.getPerAfiSafiLocRibTlv().getCount().toString(), peerStats.getPerAfiSafiLocRibRoutes().getAfiSafi().get(0).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 -> {
        assertTrue(!prePolicyRib.getTables().isEmpty());
        final Tables tables = prePolicyRib.getTables().get(0);
        assertTrue(tables.getAttributes().isUptodate());
        assertEquals(3, ((Ipv4RoutesCase) tables.getRoutes()).getIpv4Routes().getIpv4Route().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 -> {
        assertTrue(!postPolicyRib.getTables().isEmpty());
        final Tables tables = postPolicyRib.getTables().get(0);
        assertTrue(tables.getAttributes().isUptodate());
        assertEquals(3, ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.bmp.monitor.monitor.router.peer.post.policy.rib.tables.routes.Ipv4RoutesCase) tables.getRoutes()).getIpv4Routes().getIpv4Route().size());
        return tables;
    });
    waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createPeerDownNotification(PEER1)));
    readDataOperational(getDataBroker(), routerIId, router -> {
        final List<Peer> peersAfterDown = router.getPeer();
        assertTrue(peersAfterDown.isEmpty());
        return router;
    });
    return channel;
}
Also used : MockitoAnnotations(org.mockito.MockitoAnnotations) BindingReflections(org.opendaylight.yangtools.yang.binding.util.BindingReflections) RouteMirroringMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.RouteMirroringMessage) RouterId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId) RouterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.routers.RouterKey) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables) StatsReportsMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.StatsReportsMessage) Mirrors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.Mirrors) PostPolicyRib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.PostPolicyRib) PrePolicyRib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.PrePolicyRib) SocketChannel(io.netty.channel.socket.SocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) Channel(io.netty.channel.Channel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Peer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.Peer) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.routers.Router) PeerKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.PeerKey) Tlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.stat.Tlvs) PeerSession(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.PeerSession) Stats(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.Stats)

Example 82 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project bgpcep by opendaylight.

the class BmpRouterImpl method onSessionUp.

@Override
public synchronized void onSessionUp(final BmpSession psession) {
    this.session = psession;
    this.routerIp = InetAddresses.toAddrString(this.session.getRemoteAddress());
    this.routerId = new RouterId(Ipv4Util.getIpAddress(this.session.getRemoteAddress()));
    // check if this session is redundant
    if (!this.sessionManager.addSessionListener(this)) {
        LOG.warn("Redundant BMP session with remote router {} ({}) detected. This BMP session will be abandoned.", this.routerIp, this.session);
        this.close();
    } else {
        this.routerYangIId = YangInstanceIdentifier.builder(this.sessionManager.getRoutersYangIId()).nodeWithKey(Router.QNAME, ROUTER_ID_QNAME, this.routerIp).build();
        this.peersYangIId = YangInstanceIdentifier.builder(this.routerYangIId).node(Peer.QNAME).build();
        createRouterEntry();
        LOG.info("BMP session with remote router {} ({}) is up now.", this.routerIp, this.session);
    }
}
Also used : RouterId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId)

Example 83 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project bgpcep by opendaylight.

the class RouterIdParser method serializeBody.

@Override
public void serializeBody(final Esi esi, final ByteBuf body) {
    Preconditions.checkArgument(esi instanceof RouterIdGeneratedCase, "Unknown esi instance. Passed %s. Needed RouterIdGeneratedCase.", esi.getClass());
    final RouterIdGenerated routerID = ((RouterIdGeneratedCase) esi).getRouterIdGenerated();
    ByteBufWriteUtil.writeIpv4Address(routerID.getRouterId(), body);
    ByteBufWriteUtil.writeUnsignedInt(routerID.getLocalDiscriminator(), body);
    body.writeZero(ZERO_BYTE);
}
Also used : RouterIdGenerated(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.esi.router.id.generated._case.RouterIdGenerated) RouterIdGeneratedCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.esi.RouterIdGeneratedCase)

Example 84 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project bgpcep by opendaylight.

the class LocRibWriter method updateRoutesEntries.

@SuppressWarnings("unchecked")
private void updateRoutesEntries(final Collection<DataObjectModification<? extends DataObject>> routeChanges, final UnsignedInteger routerId, final Map<RouteUpdateKey, RouteEntry> routes) {
    for (final DataObjectModification<? extends DataObject> route : routeChanges) {
        final Identifier routeKey = ((InstanceIdentifier.IdentifiableItem) route.getIdentifier()).getKey();
        RouteEntry entry = this.routeEntries.get(routeKey);
        final Route newRoute = (Route) route.getDataAfter();
        final Route oldRoute = (Route) route.getDataBefore();
        if (newRoute != null) {
            if (entry == null) {
                entry = createEntry(routeKey);
            }
            final long pathId = this.ribSupport.extractPathId(newRoute);
            entry.addRoute(routerId, pathId, newRoute);
            this.totalPathsCounter.increment();
        } else if (oldRoute != null && entry != null) {
            this.totalPathsCounter.decrement();
            final long pathId = this.ribSupport.extractPathId(oldRoute);
            if (entry.removeRoute(routerId, pathId)) {
                this.routeEntries.remove(routeKey);
                this.totalPrefixesCounter.decrement();
                LOG.trace("Removed route from {}", routerId);
            }
        }
        final RouteUpdateKey routeUpdateKey = new RouteUpdateKey(routerId, routeKey);
        LOG.debug("Updated route {} entry {}", routeKey, entry);
        routes.put(routeUpdateKey, entry);
    }
}
Also used : RouteEntry(org.opendaylight.protocol.bgp.mode.api.RouteEntry) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)

Example 85 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project bgpcep by opendaylight.

the class XROUnnumberedInterfaceSubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
    final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
    final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
    body.writeZero(RESERVED);
    writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null, body);
    Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
    writeUnsignedInt(specObj.getRouterId(), body);
    Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
    writeUnsignedInt(specObj.getInterfaceId(), body);
    XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
Also used : UnnumberedCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase) ByteBuf(io.netty.buffer.ByteBuf) UnnumberedSubobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.UnnumberedSubobject)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)86 BigInteger (java.math.BigInteger)35 ArrayList (java.util.ArrayList)34 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)23 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)22 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)20 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)20 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)19 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)19 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)17 ExecutionException (java.util.concurrent.ExecutionException)16 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)14 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)12 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)12 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)12 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)11 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)11 HashSet (java.util.HashSet)10 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)10 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)10