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 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().getIpv4Address());
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());
}
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 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));
final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
phBuilder.setType(PeerType.forValue(0));
phBuilder.setAdjRibInType(AdjRibInType.forValue(1));
phBuilder.setIpv4(true);
phBuilder.setAddress(new IpAddress(new Ipv4Address("192.168.1.1")));
phBuilder.setAs(new AsNumber(168L));
phBuilder.setBgpId(new Ipv4Address("1.1.1.1"));
phBuilder.setTimestampSec(new Timestamp(16909060L));
phBuilder.setTimestampMicro(new Timestamp(16909060L));
assertEquals(perHeader, phBuilder.build());
final ByteBuf aggregator = Unpooled.buffer();
this.parser.serializePerPeerHeader(perHeader, aggregator);
assertArrayEquals(msgBytes, ByteArray.getAllBytes(aggregator));
}
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 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));
}
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 serializePerPeerHeader.
protected void serializePerPeerHeader(final PeerHeader peerHeader, final ByteBuf output) {
Preconditions.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.isIpv4());
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.isIpv4()) {
output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
ByteBufWriteUtil.writeIpv4Address(peerHeader.getAddress().getIpv4Address(), output);
} else {
ByteBufWriteUtil.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
}
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getAs().getValue(), output);
ByteBufWriteUtil.writeIpv4Address(peerHeader.getBgpId(), output);
if (peerHeader.getTimestampSec() != null) {
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampSec().getValue(), output);
} else {
output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
}
if (peerHeader.getTimestampMicro() != null) {
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampMicro().getValue(), output);
} else {
output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
}
}
Aggregations