Search in sources :

Example 6 with PeerHeader

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

the class BmpMockUtilTest method testCreateRouteMonitoringPrePolicy.

@Test
public void testCreateRouteMonitoringPrePolicy() {
    final RouteMonitoringMessage routeMonitoring = BmpMockUtil.createRouteMonitoring(PEER_IP, AdjRibInType.PrePolicy, PREFIX);
    final PeerHeader peerHeader = routeMonitoring.getPeerHeader();
    assertEquals(PEER_IP, peerHeader.getAddress().getIpv4AddressNoZone());
    assertEquals(65431L, peerHeader.getAs().getValue().longValue());
    assertEquals(PEER_IP, peerHeader.getBgpId());
    assertEquals(PeerType.Global, peerHeader.getType());
    assertEquals(AdjRibInType.PrePolicy, peerHeader.getAdjRibInType());
    final Update update = routeMonitoring.getUpdate();
    assertEquals(PREFIX, update.getNlri().get(0).getPrefix());
    assertEquals("1.2.3.4", ((Ipv4NextHopCase) update.getAttributes().getCNextHop()).getIpv4NextHop().getGlobal().getValue());
}
Also used : PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeader) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.route.monitoring.message.Update) RouteMonitoringMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.RouteMonitoringMessage) Test(org.junit.Test)

Example 7 with PeerHeader

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

the class AbstractBmpPerPeerMessageParserTest method testSerializeMessageBody.

@Test
public void testSerializeMessageBody() {
    final PeerHeader perHeader = AbstractBmpPerPeerMessageParser.parsePerPeerHeader(Unpooled.wrappedBuffer(this.ipv6MsgWithDistinguishergBytes));
    final PeerUpNotification peerNotif = new PeerUpNotificationBuilder().setPeerHeader(perHeader).build();
    final ByteBuf aggregator = Unpooled.buffer();
    this.parser.serializeMessageBody(peerNotif, aggregator);
    assertArrayEquals(this.ipv6MsgWithDistinguishergBytes, ByteArray.getAllBytes(aggregator));
}
Also used : PeerUpNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerUpNotification) PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeader) ByteBuf(io.netty.buffer.ByteBuf) PeerUpNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerUpNotificationBuilder) Test(org.junit.Test)

Example 8 with PeerHeader

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

the class AbstractBmpPerPeerMessageParserTest method testPerPeerHeader.

@Test
public void testPerPeerHeader() {
    final byte[] msgBytes = { (byte) 0x00, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, // IPV4 192.168.1.1
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01, // AS 168
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8, // Peer BGP ID 1.1.1.1
    (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, // Timestamp
    (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 };
    final PeerHeader perHeader = AbstractBmpPerPeerMessageParser.parsePerPeerHeader(Unpooled.wrappedBuffer(msgBytes));
    assertEquals(perHeader, new PeerHeaderBuilder().setType(PeerType.forValue(0)).setAdjRibInType(AdjRibInType.forValue(1)).setIpv4(true).setAddress(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.1.1"))).setAs(new AsNumber(Uint32.valueOf(168))).setBgpId(new Ipv4AddressNoZone("1.1.1.1")).setTimestampSec(new Timestamp(Uint32.valueOf(16909060))).setTimestampMicro(new Timestamp(Uint32.valueOf(16909060))).build());
    final ByteBuf aggregator = Unpooled.buffer();
    this.parser.serializePerPeerHeader(perHeader, aggregator);
    assertArrayEquals(msgBytes, ByteArray.getAllBytes(aggregator));
}
Also used : 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) 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) 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) Test(org.junit.Test)

Example 9 with PeerHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeader 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

PeerHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeader)6 Test (org.junit.Test)5 Timestamp (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)4 PeerDistinguisher (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.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 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)3 PeerHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.peer.header.PeerHeaderBuilder)3 BitArray (org.opendaylight.protocol.util.BitArray)2 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)2 PeerType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerType)2 PeerUpNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerUpNotification)2 BmpRouterPeer (org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer)1 Ipv6AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone)1 PeerId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)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 PeerDownNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerDownNotification)1 PeerUpNotificationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.PeerUpNotificationBuilder)1 RouteMonitoringMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.RouteMonitoringMessage)1