use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder in project bgpcep by opendaylight.
the class NextHopUtilTest method testSerializeNextHop.
@Test
public void testSerializeNextHop() {
CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IPV4).build()).build();
final ByteBuf buffer = Unpooled.buffer();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV4B, ByteArray.readAllBytes(buffer));
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).build()).build();
buffer.clear();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV6B, ByteArray.readAllBytes(buffer));
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).setLinkLocal(IPV6L).build()).build();
buffer.clear();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV6LB, ByteArray.readAllBytes(buffer));
buffer.clear();
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setLinkLocal(IPV6L).build()).build();
buffer.clear();
try {
NextHopUtil.serializeNextHop(hop, buffer);
fail("Exception should happen");
} catch (final IllegalArgumentException e) {
assertEquals("Ipv6 Next Hop is missing Global address.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder in project bgpcep by opendaylight.
the class BgpTestActivator method startImpl.
@Override
protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
initMock();
final List<AutoCloseable> regs = Lists.newArrayList();
regs.add(context.registerAttributeParser(TYPE, this.attrParser));
regs.add(context.registerAttributeSerializer(DataObject.class, this.attrSerializer));
regs.add(context.registerParameterParser(TYPE, this.paramParser));
regs.add(context.registerParameterSerializer(BgpParameters.class, this.paramSerializer));
regs.add(context.registerCapabilityParser(TYPE, this.capaParser));
regs.add(context.registerCapabilitySerializer(CParameters.class, this.capaSerializer));
regs.add(context.registerBgpPrefixSidTlvParser(TYPE, this.sidTlvParser));
regs.add(context.registerBgpPrefixSidTlvSerializer(BgpPrefixSidTlv.class, this.sidTlvSerializer));
regs.add(context.registerMessageParser(TYPE, this.msgParser));
regs.add(context.registerMessageSerializer(Notification.class, this.msgSerializer));
regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
this.nextHopParserSerializer = new NextHopParserSerializer() {
@Override
public CNextHop parseNextHop(final ByteBuf buffer) throws BGPParsingException {
return new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.0.0.1")).build()).build();
}
@Override
public void serializeNextHop(final CNextHop cNextHop, final ByteBuf byteAggregator) {
final byte[] mpReachBytes = { 0x7f, 0x00, 0x00, 0x01 };
byteAggregator.writeBytes(mpReachBytes);
}
};
regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv4NextHopCase.class));
regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv6NextHopCase.class));
regs.add(context.registerNlriSerializer(DataObject.class, this.nlriSerializer));
regs.add(context.registerExtendedCommunityParser(0, 0, this.exParser));
regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, this.exSerializer));
return regs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder in project bgpcep by opendaylight.
the class VpnIpv4NextHopTest method testSerializeIpv4NextHopCase.
@Test
public void testSerializeIpv4NextHopCase() throws BGPParsingException {
final ByteBuf buffer = Unpooled.buffer();
final byte[] nextHop = { 0, 0, 0, 0, 0, 0, 0, 0, 42, 42, 42, 42 };
final CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("42.42.42.42")).build()).build();
HANDLER.serializeNextHop(hop, buffer);
assertArrayEquals(nextHop, ByteArray.readAllBytes(buffer));
final CNextHop parsedHop = HANDLER.parseNextHop(Unpooled.wrappedBuffer(nextHop));
assertTrue(hop instanceof Ipv4NextHopCase);
assertEquals(hop, parsedHop);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder in project bgpcep by opendaylight.
the class BGPParserTest method testGetUpdateMessage3.
/*
* Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 4b <- length (75) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 30 <- total path attribute length (48)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- attribute length
* 02 <- Origin value (Incomplete)
* 40 <- attribute flags
* 02 <- attribute type code (as path)
* 10 <- attribute length
* 02 <- AS_SEQUENCE
* 01 <- path segment count
* 00 00 00 1e <- path segment value (30)
* 01 <- AS_SET
* 02 <- path segment count
* 00 00 00 0a <- path segment value (10)
* 00 00 00 14 <- path segment value (20)
* 40 <- attribute flags
* 03 <- attribute type (Next hop)
* 04 <- attribute length
* 0a 00 00 09 <- value (10.0.0.9)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* c0 <- attribute flags
* 07 <- attribute type (Aggregator)
* 08 <- attribute length
* 00 00 00 1e <- value (AS number = 30)
* 0a 00 00 09 <- value (IP address = 10.0.0.9)
*
* //NLRI
* 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
*/
@Test
public void testGetUpdateMessage3() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
final UpdateBuilder builder = new UpdateBuilder();
// check nlri
final List<Nlri> nlris = Lists.newArrayList(new NlriBuilder().setPrefix(new Ipv4Prefix("172.16.0.0/21")).build());
builder.setNlri(nlris);
assertEquals(builder.getNlri(), message.getNlri());
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(30L));
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final List<AsNumber> asSet = Lists.newArrayList(new AsNumber(10L), new AsNumber(20L));
asPath.add(new SegmentsBuilder().setAsSet(asSet).build());
final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(new Ipv4Address("10.0.0.9")).build();
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setCNextHop(nextHop);
assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setAggregator(aggregator);
assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
paBuilder.setUnrecognizedAttributes(Collections.emptyList());
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder in project bgpcep by opendaylight.
the class BGPParserTest method testUpdateMessageNlriAddPath.
/*
* Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI with multiple paths.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 60 <- length (96) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 31 <- total path attribute length (49)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- attribute length
* 00 <- Origin value (IGP)
* 40 <- attribute flags
* 02 <- attribute type code (as path)
* 06 <- attribute length
* 02 <- AS_SEQUENCE
* 01 <- path segment count
* 00 00 fd ea <- path segment value (65002)
* 40 <- attribute flags
* 03 <- attribute type code (Next Hop)
* 04 <- attribute length
* 0a 00 00 02 <- value (10.0.0.2)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* 40 <- attribute flags
* 06 <- attribute type code (atomic aggregate)
* 00 <- attribute length
* C0 <- attribute flags
* 08 <- attribute type code (community)
* 10 <- attribute length
* FF FF FF 01 <- value (NO_EXPORT)
* FF FF FF 02 <- value (NO_ADVERTISE)
* FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
* FF FF FF 10 <- unknown Community
*
* //NLRI
* 00 00 00 01 <- path-id (1)
* 18 ac 11 02 <- IPv4 Prefix (172.17.1.0 / 24)
* 00 00 00 01 <- path-id (2)
* 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
* 00 00 00 01 <- path-id (1)
* 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
*/
@Test
public void testUpdateMessageNlriAddPath() throws Exception {
final byte[] body = ByteArray.cutBytes(updatesWithMultiplePath.get(0), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(updatesWithMultiplePath.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, constraint);
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(65002L));
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
final List<Communities> comms = Lists.newArrayList();
comms.add((Communities) CommunityUtil.NO_EXPORT);
comms.add((Communities) CommunityUtil.NO_ADVERTISE);
comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
final UpdateBuilder builder = new UpdateBuilder();
// check nlri
final List<Nlri> nlris = Lists.newArrayList();
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(1L)).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(2L)).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.0.0/24")).setPathId(new PathId(1L)).build());
assertEquals(nlris, message.getNlri());
builder.setNlri(nlris);
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setCNextHop(nextHop);
assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
paBuilder.setCommunities(comms);
assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
paBuilder.setUnrecognizedAttributes(Collections.emptyList());
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(updatesWithMultiplePath.get(0), ByteArray.readAllBytes(buffer));
}
Aggregations