use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class PeerTest method testClassicPeer.
@Test
public void testClassicPeer() throws Exception {
this.classic = AbstractAddPathTest.configurePeer(this.tableRegistry, this.neighborAddress.getIpv4AddressNoZone(), getRib(), null, PeerRole.Ibgp, new StrictBGPPeerRegistry());
this.classic.instantiateServiceInstance();
this.mockSession();
assertEquals(this.neighborAddress.getIpv4AddressNoZone().getValue(), this.classic.getName());
this.classic.onSessionUp(this.session);
assertEquals("BGPPeer{name=127.0.0.1, tables=[TablesKey{_afi=interface org.opendaylight.yang.gen.v1" + ".urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily," + " _safi=interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types" + ".rev200120.UnicastSubsequentAddressFamily}]}", this.classic.toString());
final Nlri n1 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
final Nlri n2 = new NlriBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
final Nlri n3 = new NlriBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
final List<Nlri> nlris = Lists.newArrayList(n1, n2, n3);
final UpdateBuilder ub = new UpdateBuilder();
ub.setNlri(nlris);
final Origin origin = new OriginBuilder().setValue(BgpOrigin.Igp).build();
final AsPath asPath = new AsPathBuilder().setSegments(Collections.emptyList()).build();
final CNextHop nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("127.0.0.1")).build()).build();
final AttributesBuilder ab = new AttributesBuilder();
ub.setAttributes(ab.setOrigin(origin).setAsPath(asPath).setCNextHop(nextHop).build());
try {
this.classic.onMessage(this.session, ub.build());
fail();
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "LOCAL_PREF", e.getMessage());
assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING.getCode(), e.getError().getCode());
assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING.getSubcode(), e.getError().getSubcode());
assertArrayEquals(new byte[] { LocalPreferenceAttributeParser.TYPE }, e.getData());
}
assertEquals(0, this.routes.size());
final LocalPref localPref = new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build();
ub.setAttributes(ab.setLocalPref(localPref).build());
this.classic.onMessage(this.session, ub.build());
assertEquals(3, this.routes.size());
// create new peer so that it gets advertized routes from RIB
final BGPPeer testingPeer = AbstractAddPathTest.configurePeer(this.tableRegistry, this.neighborAddress.getIpv4AddressNoZone(), getRib(), null, PeerRole.Ibgp, new StrictBGPPeerRegistry());
testingPeer.instantiateServiceInstance();
testingPeer.onSessionUp(this.session);
assertEquals(3, this.routes.size());
final Nlri n11 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
final Nlri n22 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.16/28")).build();
final List<Nlri> nlris2 = Lists.newArrayList(n11, n22);
ub.setNlri(nlris2);
final WithdrawnRoutes w1 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
final WithdrawnRoutes w2 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
final WithdrawnRoutes w3 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
final List<WithdrawnRoutes> wrs = Lists.newArrayList(w1, w2, w3);
ub.setWithdrawnRoutes(wrs);
this.classic.onMessage(this.session, ub.build());
assertEquals(2, this.routes.size());
this.classic.onMessage(this.session, new KeepaliveBuilder().build());
this.classic.onMessage(this.session, new UpdateBuilder().setAttributes(new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(new MpUnreachNlriBuilder().setAfi(IPV4_AFI).setSafi(SAFI).build()).build()).build()).build());
this.classic.onMessage(this.session, new RouteRefreshBuilder().setAfi(IPV4_AFI).setSafi(SAFI).build());
this.classic.onMessage(this.session, new RouteRefreshBuilder().setAfi(Ipv6AddressFamily.class).setSafi(SAFI).build());
assertEquals(2, this.routes.size());
this.classic.releaseConnection();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class Ipv6NlriParser method prefixes.
private static DestinationIpv6 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraint, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
final List<Ipv6Prefixes> prefixes = new ArrayList<>();
final boolean supported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi));
while (nlri.isReadable()) {
final Ipv6PrefixesBuilder prefixesBuilder = new Ipv6PrefixesBuilder();
if (supported) {
prefixesBuilder.setPathId(PathIdUtil.readPathId(nlri));
}
prefixesBuilder.setPrefix(Ipv6Util.prefixForByteBuf(nlri));
prefixes.add(prefixesBuilder.build());
}
return new DestinationIpv6Builder().setIpv6Prefixes(prefixes).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class SimpleFlowspecIpv4NlriParserTest method testBatchedFlowspecNlri.
@Test
public void testBatchedFlowspecNlri() throws Exception {
final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
final MpReachNlriBuilder result = new MpReachNlriBuilder();
result.setAfi(Ipv4AddressFamily.class);
result.setSafi(FlowspecSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_BATCHED), result, null);
final MpReachNlri nlri = result.build();
final List<Flowspec> flowspecList = ((DestinationFlowspecCase) nlri.getAdvertizedRoutes().getDestinationType()).getDestinationFlowspecIpv4().getFlowspec();
assertEquals(3, flowspecList.size());
assertEquals("216.58.245.101/32", ((DestinationPrefixCase) flowspecList.get(0).getFlowspecType()).getDestinationPrefix().getValue());
assertEquals("216.58.218.196/32", ((DestinationPrefixCase) flowspecList.get(1).getFlowspecType()).getDestinationPrefix().getValue());
assertEquals("216.58.216.195/32", ((DestinationPrefixCase) flowspecList.get(2).getFlowspecType()).getDestinationPrefix().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class TestUtil method createNlriWitNormalizedIpv4Prefixes.
private static List<Nlri> createNlriWitNormalizedIpv4Prefixes() {
final Nlri n1 = new NlriBuilder().setPrefix(new Ipv4Prefix("10.10.10.0/24")).build();
final Nlri n2 = new NlriBuilder().setPrefix(new Ipv4Prefix("20.20.20.0/24")).build();
final Nlri n3 = new NlriBuilder().setPrefix(new Ipv4Prefix("30.30.30.0/24")).build();
return Lists.newArrayList(n1, n2, n3);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri in project bgpcep by opendaylight.
the class BGPUpdateMessageParser method parseMessageBody.
/**
* Parse Update message from buffer. Calls {@link #checkMandatoryAttributesPresence(Update, RevisedErrorHandling)}
* to check for presence of mandatory attributes.
*
* @param buffer Encoded BGP message in ByteBuf
* @param messageLength Length of the BGP message
* @param constraint Peer specific constraints
* @return Parsed Update message body
*/
@Override
public Update parseMessageBody(final ByteBuf buffer, final int messageLength, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
checkArgument(buffer != null && buffer.isReadable(), "Buffer cannot be null or empty.");
final UpdateBuilder builder = new UpdateBuilder();
final boolean isMultiPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
final RevisedErrorHandling errorHandling = RevisedErrorHandling.from(constraint);
final int withdrawnRoutesLength = buffer.readUnsignedShort();
if (withdrawnRoutesLength > 0) {
final List<WithdrawnRoutes> withdrawnRoutes = new ArrayList<>();
final ByteBuf withdrawnRoutesBuffer = buffer.readSlice(withdrawnRoutesLength);
while (withdrawnRoutesBuffer.isReadable()) {
final WithdrawnRoutesBuilder withdrawnRoutesBuilder = new WithdrawnRoutesBuilder();
if (isMultiPathSupported) {
withdrawnRoutesBuilder.setPathId(PathIdUtil.readPathId(withdrawnRoutesBuffer));
}
withdrawnRoutesBuilder.setPrefix(readPrefix(withdrawnRoutesBuffer, errorHandling, "Withdrawn Routes"));
withdrawnRoutes.add(withdrawnRoutesBuilder.build());
}
builder.setWithdrawnRoutes(withdrawnRoutes);
}
final int totalPathAttrLength = buffer.readUnsignedShort();
if (withdrawnRoutesLength == 0 && totalPathAttrLength == 0) {
return builder.build();
}
Optional<BGPTreatAsWithdrawException> withdrawCauseOpt;
if (totalPathAttrLength > 0) {
final ParsedAttributes attributes = parseAttributes(buffer, totalPathAttrLength, constraint);
builder.setAttributes(attributes.getAttributes());
withdrawCauseOpt = attributes.getWithdrawCause();
} else {
withdrawCauseOpt = Optional.empty();
}
final List<Nlri> nlri = new ArrayList<>();
while (buffer.isReadable()) {
final NlriBuilder nlriBuilder = new NlriBuilder();
if (isMultiPathSupported) {
nlriBuilder.setPathId(PathIdUtil.readPathId(buffer));
}
nlriBuilder.setPrefix(readPrefix(buffer, errorHandling, "NLRI"));
nlri.add(nlriBuilder.build());
}
if (!nlri.isEmpty()) {
builder.setNlri(nlri);
}
try {
checkMandatoryAttributesPresence(builder.build(), errorHandling);
} catch (BGPTreatAsWithdrawException e) {
LOG.debug("Well-known mandatory attributes missing", e);
if (withdrawCauseOpt.isPresent()) {
final BGPTreatAsWithdrawException exception = withdrawCauseOpt.get();
exception.addSuppressed(e);
withdrawCauseOpt = Optional.of(exception);
} else {
withdrawCauseOpt = Optional.of(e);
}
}
Update msg = builder.build();
if (withdrawCauseOpt.isPresent()) {
// Attempt to apply treat-as-withdraw
msg = withdrawUpdate(msg, errorHandling, withdrawCauseOpt.get());
}
LOG.debug("BGP Update message was parsed {}.", msg);
return msg;
}
Aggregations