use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.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();
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));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.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);
final StringBuilder routeDistiguisher = new StringBuilder();
switch(rdType) {
case AS_2BYTE:
routeDistiguisher.append(type);
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedShort());
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedInt());
return new RouteDistinguisher(new RdTwoOctetAs(routeDistiguisher.toString()));
case IPV4:
routeDistiguisher.append(Ipv4Util.addressForByteBuf(buffer).getValue());
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedShort());
return new RouteDistinguisher(new RdIpv4(routeDistiguisher.toString()));
case AS_4BYTE:
routeDistiguisher.append(buffer.readUnsignedInt());
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedShort());
return new RouteDistinguisher(new RdAs(routeDistiguisher.toString()));
default:
// in order to get the byte index correct
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.toString());
throw new IllegalArgumentException("Invalid Route Distinguisher type " + type);
}
}
Aggregations