Search in sources :

Example 1 with PeerDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Peer.PeerDistinguisher in project bgpcep by opendaylight.

the class BmpRouterPeerImpl method createPeerEntry.

private MapEntryNode createPeerEntry(final PeerUpNotification peerUp) {
    final PeerHeader peerHeader = peerUp.getPeerHeader();
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(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.rev200120.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.rev200120.Peer.PeerDistinguisher)

Example 2 with PeerDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Peer.PeerDistinguisher in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParser method parsePerPeerHeader.

protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
    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.getIpv4()) {
        bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
        phBuilder.setAddress(new IpAddressNoZone(Ipv4Util.addressForByteBuf(bytes)));
    } else {
        phBuilder.setAddress(new IpAddressNoZone(Ipv6Util.addressForByteBuf(bytes)));
    }
    phBuilder.setAs(new AsNumber(ByteBufUtils.readUint32(bytes)));
    phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes));
    phBuilder.setTimestampSec(new Timestamp(ByteBufUtils.readUint32(bytes)));
    phBuilder.setTimestampMicro(new Timestamp(ByteBufUtils.readUint32(bytes)));
    return phBuilder.build();
}
Also used : PeerType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerType) BitArray(org.opendaylight.protocol.util.BitArray) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeaderBuilder) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.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)

Example 3 with PeerDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Peer.PeerDistinguisher 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().setType(PeerType.L3vpn).setPeerDistinguisher(new PeerDistinguisher(new RouteDistinguisher(new RdTwoOctetAs("0:" + RD)))).setAdjRibInType(AdjRibInType.forValue(1)).setIpv4(false).setAddress(new IpAddressNoZone(new Ipv6AddressNoZone("2001::1"))).setAs(new AsNumber(Uint32.valueOf(168))).setBgpId(new Ipv4AddressNoZone("1.1.1.2")).setTimestampSec(new Timestamp(Uint32.ZERO)).setTimestampMicro(new Timestamp(Uint32.ZERO));
    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.rev200120.RdTwoOctetAs) PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeader) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeaderBuilder) ByteBuf(io.netty.buffer.ByteBuf) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.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) Ipv6AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone) Test(org.junit.Test)

Example 4 with PeerDistinguisher

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Peer.PeerDistinguisher in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParser method serializePerPeerHeader.

protected void serializePerPeerHeader(final PeerHeader peerHeader, final ByteBuf output) {
    checkArgument(peerHeader != null, "Per-peer header cannot be null.");
    final PeerType peerType = peerHeader.getType();
    output.writeByte(peerType.getIntValue());
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(L_FLAG_POS, peerHeader.getAdjRibInType().getIntValue() != 0);
    flags.set(V_FLAG_POS, !peerHeader.getIpv4());
    flags.toByteBuf(output);
    final PeerDistinguisher peerDistinguisher = peerHeader.getPeerDistinguisher();
    switch(peerType) {
        case L3vpn:
            RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output);
            break;
        case Local:
            output.writeBytes(peerDistinguisher.getBinary());
            break;
        case Global:
        default:
            output.writeZero(PEER_DISTINGUISHER_SIZE);
            break;
    }
    if (peerHeader.getIpv4()) {
        output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
        Ipv4Util.writeIpv4Address(peerHeader.getAddress().getIpv4AddressNoZone(), output);
    } else {
        Ipv6Util.writeIpv6Address(peerHeader.getAddress().getIpv6AddressNoZone(), output);
    }
    ByteBufUtils.write(output, peerHeader.getAs().getValue());
    Ipv4Util.writeIpv4Address(peerHeader.getBgpId(), output);
    final Timestamp stampSec = peerHeader.getTimestampSec();
    if (stampSec != null) {
        ByteBufUtils.write(output, stampSec.getValue());
    } else {
        output.writeInt(0);
    }
    final Timestamp stampMicro = peerHeader.getTimestampMicro();
    if (stampMicro != null) {
        ByteBufUtils.write(output, stampMicro.getValue());
    } else {
        output.writeInt(0);
    }
}
Also used : PeerType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerType) BitArray(org.opendaylight.protocol.util.BitArray) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Peer.PeerDistinguisher) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)

Aggregations

PeerDistinguisher (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Peer.PeerDistinguisher)4 Timestamp (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)3 BitArray (org.opendaylight.protocol.util.BitArray)2 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)2 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)2 PeerType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerType)2 PeerHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeader)2 PeerHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeaderBuilder)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)1 Ipv6AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)1 RdTwoOctetAs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdTwoOctetAs)1 RouteDistinguisher (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)1 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)1