use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdTwoOctetAs 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));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdTwoOctetAs in project bgpcep by opendaylight.
the class RouteDistinguisherUtil method parseRouteDistinguisher.
/**
* Parses three types of route distinguisher from given ByteBuf.
*/
public static RouteDistinguisher parseRouteDistinguisher(final ByteBuf buffer) {
Preconditions.checkState(buffer != null && buffer.isReadable(RD_LENGTH), "Cannot read Route Distinguisher from provided buffer.");
final int type = buffer.readUnsignedShort();
final RDType rdType = RDType.valueOf(type);
switch(rdType) {
case AS_2BYTE:
return new RouteDistinguisher(new RdTwoOctetAs(new StringBuilder().append(type).append(SEPARATOR).append(buffer.readUnsignedShort()).append(SEPARATOR).append(buffer.readUnsignedInt()).toString()));
case IPV4:
return new RouteDistinguisher(new RdIpv4(new StringBuilder().append(Ipv4Util.addressForByteBuf(buffer).getValue()).append(SEPARATOR).append(buffer.readUnsignedShort()).toString()));
case AS_4BYTE:
return new RouteDistinguisher(new RdAs(new StringBuilder().append(buffer.readUnsignedInt()).append(SEPARATOR).append(buffer.readUnsignedShort()).toString()));
default:
// now that this RD type is not supported, we want to read the remain 6 bytes
// in order to get the byte index correct
final StringBuilder routeDistiguisher = new StringBuilder();
for (int i = 0; i < 6; i++) {
routeDistiguisher.append("0x").append(Integer.toHexString(buffer.readByte() & 0xFF)).append(' ');
}
LOG.debug("Invalid Route Distinguisher: type={}, rawRouteDistinguisherValue={}", type, routeDistiguisher);
throw new IllegalArgumentException("Invalid Route Distinguisher type " + type);
}
}
Aggregations