use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute 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.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class BGPParserTest method testParseUpdateMessageWithMalformedAttributes.
/*
* Tests withdrawn routes with malformed attribute.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 36 <- length (54) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 1b <- total path attribute length (27)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- WRONG attribute length
* 00 <- Origin value (IGP)
* 40 <- attribute flags
* 03 <- attribute type code (Next Hop)
* 04 <- attribute length
* 0a 00 00 02 <- value (10.0.0.2)
* 40 <- attribute flags
* 0e <- attribute type code (MP_REACH)
* 0d <- attribute length
* 00 01 <- AFI (Ipv4)
* 01 <- SAFI (Unicast)
* 04 <- next hop length
* ff ff ff ff <- next hop
* 00 <- reserved
* 18 <- length
* 0a 00 01 <- prefix (10.0.1.0)
* //NLRI
* 18 <- length
* 0a 00 02 <- prefix (10.0.2.0)
*/
@Test
public void testParseUpdateMessageWithMalformedAttributes() throws Exception {
final PeerSpecificParserConstraintImpl constraint = new PeerSpecificParserConstraintImpl();
constraint.addPeerConstraint(RevisedErrorHandlingSupport.class, RevisedErrorHandlingSupportImpl.forExternalPeer());
final Update message = (Update) messageRegistry.parseMessage(Unpooled.wrappedBuffer(input.get(0)), constraint);
assertNotNull(message);
assertNull(message.getNlri());
final List<WithdrawnRoutes> withdrawnRoutes = message.getWithdrawnRoutes();
assertNotNull(withdrawnRoutes);
assertEquals(1, withdrawnRoutes.size());
final Attributes attributes = message.getAttributes();
assertNotNull(attributes);
assertNull(attributes.augmentation(AttributesReach.class));
final AttributesUnreach AttributesUnreach = attributes.augmentation(AttributesUnreach.class);
assertNotNull(AttributesUnreach);
final MpUnreachNlri mpUnreachNlri = AttributesUnreach.getMpUnreachNlri();
assertNotNull(mpUnreachNlri);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class BGPParserTest method testIPv6Nlri.
/*
* Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 80 <- length (128) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 69 <- total path attribute length (105)
* 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 e9 <- path segment value (65001)
* 40 <- attribute flags
* 03 <- attribute type code (next hop)
* 04 <- attribute length
* 0a 00 00 00 <- next hop value (10.0.0.0)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* 80 <- attribute flags
* 09 <- attribute type code (originator id)
* 04 <- attribute length
* 7f 00 00 01 <- value (localhost ip)
* 80 <- attribute flags
* 0a <- attribute type code (cluster list)
* 08 <- attribute length
* 01 02 03 04 <- value
* 05 06 07 08 <- value
* 80 <- attribute flags
* 0e <- attribute type code (mp reach nlri)
* 40 <- attribute length
* 00 02 <- AFI (Ipv6)
* 01 <- SAFI (Unicast)
* 20 <- length of next hop
* 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
* fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
* 00 <- reserved
*
* //NLRI
* 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
* 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
* 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
*
*/
@Test
public void testIPv6Nlri() throws Exception {
final Update message = (Update) messageRegistry.parseMessage(Unpooled.wrappedBuffer(input.get(1)), null);
// check fields
assertNull(message.getWithdrawnRoutes());
final UpdateBuilder builder = new UpdateBuilder();
// check NLRI
final List<Ipv6Prefixes> prefs = new ArrayList<>();
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build());
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:1::/64")).build());
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1::/64")).build());
assertNull(message.getNlri());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(Uint32.valueOf(65001)));
final List<Segments> asPath = new ArrayList<>();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6AddressNoZone("2001:db8::1")).setLinkLocal(new Ipv6AddressNoZone("fe80::c001:bff:fe7e:0")).build()).build();
final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4AddressNoZone("1.2.3.4")), new ClusterIdentifier(new Ipv4AddressNoZone("5.6.7.8")));
// 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.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4AddressNoZone("127.0.0.1")).build());
assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build());
assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setCNextHop(nextHop).setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
paBuilder.addAugmentation(new AttributesReachBuilder().setMpReachNlri(mpBuilder.build()).build());
assertEquals(paBuilder.augmentation(AttributesReach.class).getMpReachNlri(), attrs.augmentation(AttributesReach.class).getMpReachNlri());
paBuilder.setUnrecognizedAttributes(Collections.emptyMap());
// check API message
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
messageRegistry.serializeMessage(message, buffer);
assertArrayEquals(input.get(1), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class PEDistinguisherLabelsAttributeHandler method serializeAttribute.
@Override
public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
final PeDistinguisherLabelsAttributeAugmentation att = attribute.augmentation(PeDistinguisherLabelsAttributeAugmentation.class);
if (att == null) {
return;
}
final List<PeDistinguisherLabelAttribute> distinguishers = att.getPeDistinguisherLabelsAttribute().getPeDistinguisherLabelAttribute();
final ByteBuf buffer = Unpooled.buffer();
for (final PeDistinguisherLabelAttribute peDist : distinguishers) {
if (peDist.getPeAddress().getIpv4AddressNoZone() != null) {
buffer.writeBytes(Ipv4Util.bytesForAddress(peDist.getPeAddress().getIpv4AddressNoZone()));
} else {
buffer.writeBytes(Ipv6Util.bytesForAddress(peDist.getPeAddress().getIpv6AddressNoZone()));
}
buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabel(peDist.getMplsLabel()));
}
formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, buffer, byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class ParserTest method testEORLS.
/*
* End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 1d <- length (29) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 06 <- total path attribute length
* 80 <- attribute flags
* 0f <- attribute type (15 - MP_UNREACH_NLRI)
* 03 <- attribute length
* 40 04 <- value (AFI 16388: LS)
* 47 <- value (SAFI 71)
*/
@Test
public void testEORLS() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(0), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
final Class<? extends AddressFamily> afi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getAfi();
final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getSafi();
assertEquals(LinkstateAddressFamily.class, afi);
assertEquals(LinkstateSubsequentAddressFamily.class, safi);
final ByteBuf buffer = Unpooled.buffer();
ParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(INPUT_BYTES.get(0), ByteArray.readAllBytes(buffer));
}
Aggregations