use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class LUNlriParserTest method testMpReachNlriIpv6Constraint.
@Test
public void testMpReachNlriIpv6Constraint() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(Ipv6AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
final MpReachNlri mpReachExpected = mpBuilder.build();
// test parser
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv6AddressFamily.class);
testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
assertEquals(mpReachExpected, testBuilder.build());
// test serializer
final ByteBuf output = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
assertArrayEquals(LU_REACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class LUNlriParserTest method testMpReachNlriIpv4.
@Test
public void testMpReachNlriIpv4() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(Ipv4AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
final MpReachNlri mpReachExpected = mpBuilder.build();
// test parser
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv4AddressFamily.class);
testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4), testBuilder);
assertEquals(mpReachExpected, testBuilder.build());
// test serializer
final ByteBuf output = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
assertArrayEquals(LU_REACH_NLRI_IPv4, ByteArray.readAllBytes(output));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class BGPPeer method nextHopToAttribute.
private static Attributes nextHopToAttribute(final Attributes attrs, final MpReachNlri mpReach) {
if (attrs.getCNextHop() == null && mpReach.getCNextHop() != null) {
final AttributesBuilder attributesBuilder = new AttributesBuilder(attrs);
attributesBuilder.setCNextHop(mpReach.getCNextHop());
return attributesBuilder.build();
}
return attrs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class AbstractRIBSupport method buildUpdate.
@Nonnull
@Override
public final Update buildUpdate(final Collection<MapEntryNode> advertised, final Collection<MapEntryNode> withdrawn, final Attributes attr) {
final UpdateBuilder ub = new UpdateBuilder();
final AttributesBuilder ab = new AttributesBuilder(attr);
final CNextHop hop = ab.getCNextHop();
LOG.debug("cnextHop before={}", hop);
// do not preserve next hop in attributes if we are using MpReach
ab.setCNextHop(null);
if (!advertised.isEmpty()) {
final MpReachNlri mb = buildReach(advertised, hop);
ab.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mb).build());
LOG.debug("mpreach nexthop={}", mb);
}
if (!withdrawn.isEmpty()) {
final MpUnreachNlri mb = buildUnreach(withdrawn);
ab.addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mb).build());
LOG.debug("mpunrach mb={}", mb);
}
ub.setAttributes(ab.build());
LOG.debug("update {}", ub.build());
return ub.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri in project bgpcep by opendaylight.
the class ParserTest method testBGPNode.
/*
* TEST BGP Node
*
* 00 00 <- withdrawn routes length
00 b1 <- total path attribute length (177)
80 <- attribute flags
0e <- attribute type code (MP reach)
a0 <- attribute length (160)
40 04 <- AFI (16388 - Linkstate)
47 <- SAFI (71 - Linkstate)
04 <- next hop length
19 19 19 01 - nexthop (25.25.25.1)
00 <- reserved
00 01 <- NLRI type (1 - nodeNLRI)
00 31 <- NLRI length (49)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
01 00 <- local node descriptor type (256)
00 24 <- length (36)
02 00 <- node descriptor type (member AS - 512)
00 04 <- length
00 00 00 64 <- value (100)
02 01 <- node descriptor type (bgpId - 513)
00 04 <- length
19 19 19 01 <- bgpId (25.25.25.1)
02 02 <- node descriptor type (areaId - 514)
00 04 <- length
00 00 00 00 <- value
02 03 <- node descriptor type (routeId - 515)
00 08 <- length
03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
00 01 <- NLRI type (1 - nodeNLRI)
00 2d <- NLRI length (45)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
01 00 <- local node descriptor type (256)
00 20 <- length (32)
02 00 <- node descriptor type (member AS - 512)
00 04 <- length
00 00 00 64 <- value (100)
02 01 <- node descriptor type (bgpId - 513)
00 04 <- length
19 19 19 01 <- bgpId (25.25.25.1)
02 02 <- node descriptor type (areaId - 514)
00 04 <- length
00 00 00 00 <- value
02 03 <- node descriptor type (routeId - 515)
00 04 <- length
03 03 03 04 <- OSPF Router Id
00 01 <- NLRI type (1 - nodeNLRI)
00 2d <- NLRI length (45)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
01 00 <- local node descriptor type (256)
00 20 <- length (32)
02 00 <- node descriptor type (member AS - 512)
00 04 <- length
00 00 00 64 <- value (100)
02 01 <- node descriptor type (bgpId - 513)
00 04 <- length
19 19 19 01 <- bgpId (25.25.25.1)
02 02 <- node descriptor type (areaId - 514)
00 04 <- length
00 00 00 00 <- value
02 03 <- node descriptor type (routeId - 515)
00 04 <- length
01 01 01 02 <- OSPF Router Id
40 <- attribute flags
01 <- attribute type (Origin)
01 <- attribute length
00 <- value (IGP)
40 <- attribute flags
02 <- attribute type (AS Path)
00 <- length
40 <- attribute flags
05 <- attribute type (local pref)
04 <- length
00 00 00 64 <- value
*/
@Test
public void testBGPNode() 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 = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
final UpdateBuilder builder = new UpdateBuilder();
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
clBuilder.setProtocolId(ProtocolId.Ospf);
final NodeDescriptorsBuilder n = new NodeDescriptorsBuilder();
n.setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
final List<CLinkstateDestination> linkstates = Lists.newArrayList();
final NodeCaseBuilder nCase = new NodeCaseBuilder();
nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
linkstates.add(clBuilder.setObjectType(nCase.build()).build());
nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
linkstates.add(clBuilder.setObjectType(nCase.build()).build());
nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
linkstates.add(clBuilder.setObjectType(nCase.build()).build());
final Attributes1Builder lsBuilder = new Attributes1Builder();
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(LinkstateAddressFamily.class);
mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
mpBuilder.setCNextHop(nextHop);
final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
dBuilder.setCLinkstateDestination(linkstates);
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
lsBuilder.setMpReachNlri(mpBuilder.build());
// 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(Collections.emptyList()).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
paBuilder.setUnrecognizedAttributes(Collections.emptyList());
final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
assertEquals(mpBuilder.getAfi(), mp.getAfi());
assertEquals(mpBuilder.getSafi(), mp.getSafi());
assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
assertEquals(linkstates.size(), dests.size());
assertEquals(linkstates, dests);
// check API message
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
ParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
}
Aggregations