use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.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.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.
the class BGPMessageParserMockTest method fillMessages.
/**
* Helper method to fill messages variable.
*
* @param asn this parameter is passed to ASNumber constructor
*/
private static Update fillMessages(final long asn) {
final UpdateBuilder builder = new UpdateBuilder();
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setAsSequence(Lists.newArrayList(new AsNumber(asn))).build());
final CNextHop nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
final Ipv6Prefix pref1 = new Ipv6Prefix("2001:db8:1:2::/64");
final Ipv6Prefix pref2 = new Ipv6Prefix("2001:db8:1:1::/64");
final Ipv6Prefix pref3 = new Ipv6Prefix("2001:db8:1::/64");
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
final MpReachNlriBuilder mpReachBuilder = new MpReachNlriBuilder();
mpReachBuilder.setAfi(Ipv6AddressFamily.class);
mpReachBuilder.setSafi(UnicastSubsequentAddressFamily.class);
mpReachBuilder.setCNextHop(nextHop);
mpReachBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(new Ipv6PrefixesBuilder().setPrefix(pref1).build(), new Ipv6PrefixesBuilder().setPrefix(pref2).build(), new Ipv6PrefixesBuilder().setPrefix(pref3).build())).build()).build()).build());
paBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReachBuilder.build()).build());
builder.setAttributes(paBuilder.build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.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.rev130919.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 Ipv4Address("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.rev130919.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);
}
Aggregations