use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop in project bgpcep by opendaylight.
the class VpnIpv6NextHopTest method testSerializeIpv6NextHopCase.
@Test
public void testSerializeIpv6NextHopCase() throws Exception {
// put some random valid IPv6 address here
final String TEST_IPV6 = "2001::1234:5678:90ab:cdef";
final ByteBuf buffer = Unpooled.buffer();
final byte[] nextHop = new byte[Ipv6Util.IPV6_LENGTH + RouteDistinguisherUtil.RD_LENGTH];
// now copy the IPv6 address to the byte array
System.arraycopy(Inet6Address.getByName(TEST_IPV6).getAddress(), 0, nextHop, RouteDistinguisherUtil.RD_LENGTH, Ipv6Util.IPV6_LENGTH);
final CNextHop hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6Address(TEST_IPV6)).build()).build();
HANDLER.serializeNextHop(hop, buffer);
assertArrayEquals(nextHop, ByteArray.readAllBytes(buffer));
final CNextHop parsedHop = HANDLER.parseNextHop(Unpooled.wrappedBuffer(nextHop));
assertTrue(hop instanceof Ipv6NextHopCase);
assertEquals(hop, parsedHop);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop in project bgpcep by opendaylight.
the class NextHopAttributeParser method serializeAttribute.
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
final CNextHop cNextHop = ((Attributes) attribute).getCNextHop();
if (cNextHop == null) {
return;
}
final ByteBuf nextHopBuffer = Unpooled.buffer();
NextHopUtil.serializeNextHop(cNextHop, nextHopBuffer);
AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, nextHopBuffer, byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop in project bgpcep by opendaylight.
the class NextHopUtilTest method testParseNextHop.
@Test
public void testParseNextHop() {
CNextHop hop = null;
try {
hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(IPV4B));
} catch (final IllegalArgumentException e) {
fail("This exception should not happen");
}
assertEquals(IPV4, ((Ipv4NextHopCase) hop).getIpv4NextHop().getGlobal());
try {
hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(IPV6B));
} catch (final IllegalArgumentException e) {
fail("This exception should not happen");
}
assertEquals(IPV6, ((Ipv6NextHopCase) hop).getIpv6NextHop().getGlobal());
assertNull(((Ipv6NextHopCase) hop).getIpv6NextHop().getLinkLocal());
try {
hop = NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(IPV6LB));
} catch (final IllegalArgumentException e) {
fail("This exception should not happen");
}
assertEquals(IPV6, ((Ipv6NextHopCase) hop).getIpv6NextHop().getGlobal());
assertEquals(IPV6L, ((Ipv6NextHopCase) hop).getIpv6NextHop().getLinkLocal());
final byte[] wrong = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d };
try {
NextHopUtil.parseNextHop(Unpooled.wrappedBuffer(wrong));
fail("Exception should happen");
} catch (final IllegalArgumentException e) {
assertEquals("Cannot parse NEXT_HOP attribute. Wrong bytes length: 3", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop in project bgpcep by opendaylight.
the class NextHopParserSerializerTest method testSerializeIpv4NextHopCase.
@Test
public void testSerializeIpv4NextHopCase() throws BGPParsingException {
final byte[] ipv4B = { 42, 42, 42, 42 };
this.hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("42.42.42.42")).build()).build();
this.ipv4NextHopParserSerializer.serializeNextHop(this.hop, this.buffer);
assertArrayEquals(ipv4B, ByteArray.readAllBytes(this.buffer));
final CNextHop parsedHop = this.ipv4NextHopParserSerializer.parseNextHop(Unpooled.wrappedBuffer(ipv4B));
assertTrue(this.hop instanceof Ipv4NextHopCase);
assertEquals(this.hop, parsedHop);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop in project bgpcep by opendaylight.
the class NextHopAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
final CNextHop nextHop;
switch(readable) {
case IP4_LENGTH:
nextHop = NextHopUtil.parseNextHopIpv4(buffer);
break;
case IPV6_LENGTH:
nextHop = NextHopUtil.parseNextHopIpv6(buffer);
break;
case IPV6_LENGTH * 2:
nextHop = NextHopUtil.parseNextHopFullIpv6(buffer);
break;
default:
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "NEXT_HOP attribute is expected to have length of {%s, %s, %s} but has %s", IP4_LENGTH, IPV6_LENGTH, IPV6_LENGTH * 2, readable);
}
builder.setCNextHop(nextHop);
}
Aggregations