Search in sources :

Example 1 with PeerHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader in project bgpcep by opendaylight.

the class BmpRouterPeerImpl method createPeerEntry.

private MapEntryNode createPeerEntry(final PeerUpNotification peerUp) {
    final PeerHeader peerHeader = peerUp.getPeerHeader();
    final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(Peer.QNAME, PEER_ID_QNAME, this.peerId.getValue())).withChild(ImmutableNodes.leafNode(PEER_ID_QNAME, this.peerId.getValue())).withChild(ImmutableNodes.leafNode(PEER_TYPE_QNAME, peerHeader.getType().name().toLowerCase(Locale.ENGLISH))).withChild(ImmutableNodes.leafNode(PEER_ADDRESS_QNAME, getStringIpAddress(peerHeader.getAddress()))).withChild(ImmutableNodes.leafNode(PEER_AS_QNAME, peerHeader.getAs().getValue())).withChild(ImmutableNodes.leafNode(PEER_BGP_ID_QNAME, peerHeader.getBgpId().getValue())).withChild(createPeerSessionUp(peerUp, peerHeader.getTimestampSec())).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(PrePolicyRib.QNAME)).withChild(ImmutableNodes.mapNodeBuilder(BMP_TABLES_QNAME).build()).build()).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(PostPolicyRib.QNAME)).withChild(ImmutableNodes.mapNodeBuilder(BMP_TABLES_QNAME).build()).build());
    final PeerDistinguisher pd = peerHeader.getPeerDistinguisher();
    if (pd != null) {
        mapEntryBuilder.withChild(ImmutableNodes.leafNode(PEER_DISTINGUISHER_QNAME, pd.getRouteDistinguisher()));
    }
    return mapEntryBuilder.build();
}
Also used : PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher)

Example 2 with PeerHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader in project bgpcep by opendaylight.

the class BmpRouterImpl method delegateToPeer.

private synchronized void delegateToPeer(final Notification perPeerMessage) {
    final PeerId peerId = getPeerId((PeerHeader) perPeerMessage);
    final Optional<BmpRouterPeer> maybePeer = getPeer(peerId);
    if (maybePeer.isPresent()) {
        maybePeer.get().onPeerMessage(perPeerMessage);
        if (perPeerMessage instanceof PeerDownNotification) {
            this.peers.remove(peerId);
            LOG.debug("Router {}: Peer {} removed.", this.routerIp, peerId.getValue());
        }
    } else {
        LOG.debug("Peer: {} for Router: {} was not found.", peerId.getValue(), this.routerIp);
    }
}
Also used : PeerDownNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification) BmpRouterPeer(org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId)

Example 3 with PeerHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader in project bgpcep by opendaylight.

the class BmpMockUtilTest method testCreatePeerUp.

@Test
public void testCreatePeerUp() {
    final PeerUpNotification peerUp = BmpMockUtil.createPeerUp(PEER_IP, LOCAL_ADDRESS);
    final PeerHeader peerHeader = peerUp.getPeerHeader();
    assertEquals(PEER_IP, peerHeader.getAddress().getIpv4Address());
    assertEquals(65431L, peerHeader.getAs().getValue().longValue());
    assertEquals(PEER_IP, peerHeader.getBgpId());
    assertEquals(PeerType.Global, peerHeader.getType());
    assertNull(peerUp.getInformation());
    assertEquals(LOCAL_ADDRESS.getHostAddress(), peerUp.getLocalAddress().getIpv4Address().getValue());
    assertEquals(179, peerUp.getLocalPort().getValue().intValue());
    assertEquals(179, peerUp.getRemotePort().getValue().intValue());
    assertNotNull(peerUp.getReceivedOpen());
    assertNotNull(peerUp.getSentOpen());
}
Also used : PeerUpNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotification) PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader) Test(org.junit.Test)

Example 4 with PeerHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParserTest method testPerPeerHeaderIpv6.

@Test
public void testPerPeerHeaderIpv6() {
    final PeerHeader perHeader = AbstractBmpPerPeerMessageParser.parsePerPeerHeader(Unpooled.wrappedBuffer(this.ipv6MsgWithDistinguishergBytes));
    final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
    phBuilder.setType(PeerType.L3vpn);
    phBuilder.setPeerDistinguisher(new PeerDistinguisher(new RouteDistinguisher(new RdTwoOctetAs("0:" + RD))));
    phBuilder.setAdjRibInType(AdjRibInType.forValue(1));
    phBuilder.setIpv4(false);
    phBuilder.setAddress(new IpAddress(new Ipv6Address("2001::1")));
    phBuilder.setAs(new AsNumber(168L));
    phBuilder.setBgpId(new Ipv4Address("1.1.1.2"));
    phBuilder.setTimestampSec(new Timestamp(0L));
    phBuilder.setTimestampMicro(new Timestamp(0L));
    assertEquals(phBuilder.build(), perHeader);
    final ByteBuf aggregator = Unpooled.buffer();
    phBuilder.setTimestampSec(null);
    phBuilder.setTimestampMicro(null);
    this.parser.serializePerPeerHeader(phBuilder.build(), aggregator);
    assertArrayEquals(this.ipv6MsgWithDistinguishergBytes, ByteArray.getAllBytes(aggregator));
}
Also used : RdTwoOctetAs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RdTwoOctetAs) PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader) RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) ByteBuf(io.netty.buffer.ByteBuf) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 5 with PeerHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParser method parsePerPeerHeader.

protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
    Preconditions.checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
    final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
    final PeerType peerType = PeerType.forValue(bytes.readByte());
    phBuilder.setType(peerType);
    final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
    phBuilder.setAdjRibInType(AdjRibInType.forValue(flags.get(L_FLAG_POS) ? 1 : 0));
    phBuilder.setIpv4(!flags.get(V_FLAG_POS));
    switch(peerType) {
        case L3vpn:
            phBuilder.setPeerDistinguisher(new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
            break;
        case Local:
            phBuilder.setPeerDistinguisher(new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
            break;
        case Global:
        default:
            bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
            break;
    }
    if (phBuilder.isIpv4()) {
        bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
        phBuilder.setAddress(new IpAddress(Ipv4Util.addressForByteBuf(bytes)));
    } else {
        phBuilder.setAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes)));
    }
    phBuilder.setAs(new AsNumber(bytes.readUnsignedInt()));
    phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes));
    phBuilder.setTimestampSec(new Timestamp(bytes.readUnsignedInt()));
    phBuilder.setTimestampMicro(new Timestamp(bytes.readUnsignedInt()));
    return phBuilder.build();
}
Also used : PeerType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerType) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) BitArray(org.opendaylight.protocol.util.BitArray) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)

Aggregations

PeerHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader)6 Test (org.junit.Test)5 PeerDistinguisher (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher)4 ByteBuf (io.netty.buffer.ByteBuf)3 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)3 Timestamp (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)3 PeerHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder)3 BitArray (org.opendaylight.protocol.util.BitArray)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2 PeerType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerType)2 PeerUpNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotification)2 BmpRouterPeer (org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer)1 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)1 PeerId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId)1 RdTwoOctetAs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RdTwoOctetAs)1 RouteDistinguisher (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher)1 PeerDownNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification)1 PeerUpNotificationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerUpNotificationBuilder)1 RouteMonitoringMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.RouteMonitoringMessage)1