use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri in project bgpcep by opendaylight.
the class BGPPeer method onUpdateMessage.
/**
* Process Update message received.
* Calls {@link #checkMandatoryAttributesPresence(Update)} to check for presence of mandatory attributes.
*
* @param message Update message
*/
private synchronized void onUpdateMessage(final Update message) throws BGPDocumentedException {
checkMandatoryAttributesPresence(message);
// update AdjRibs
final Attributes attrs = message.getAttributes();
MpReachNlri mpReach;
final boolean isAnyNlriAnnounced = message.getNlri() != null;
if (isAnyNlriAnnounced) {
mpReach = prefixesToMpReach(message);
} else {
mpReach = MessageUtil.getMpReachNlri(attrs);
}
if (mpReach != null) {
this.ribWriter.updateRoutes(mpReach, nextHopToAttribute(attrs, mpReach));
}
final MpUnreachNlri mpUnreach;
if (message.getWithdrawnRoutes() != null) {
mpUnreach = prefixesToMpUnreach(message, isAnyNlriAnnounced);
} else {
mpUnreach = MessageUtil.getMpUnreachNlri(attrs);
}
final boolean endOfRib = BgpPeerUtil.isEndOfRib(message);
if (mpUnreach != null) {
if (endOfRib) {
final TablesKey tablesKey = new TablesKey(mpUnreach.getAfi(), mpUnreach.getSafi());
this.ribWriter.removeStaleRoutes(tablesKey);
this.missingEOT.remove(tablesKey);
handleGracefulEndOfRib();
} else {
this.ribWriter.removeRoutes(mpUnreach);
}
} else if (endOfRib) {
this.ribWriter.removeStaleRoutes(IPV4_UCAST_TABLE_KEY);
this.missingEOT.remove(IPV4_UCAST_TABLE_KEY);
handleGracefulEndOfRib();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri in project bgpcep by opendaylight.
the class AdjRibInWriter method removeRoutes.
void removeRoutes(final MpUnreachNlri nlri) {
final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
final TableContext ctx = this.tables.get(key);
if (ctx == null) {
LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
return;
}
LOG.trace("Removing routes {}", nlri);
final DOMDataTreeWriteTransaction tx = this.chain.getDomChain().newWriteOnlyTransaction();
ctx.removeRoutes(tx, nlri);
final FluentFuture<? extends CommitInfo> future = tx.commit();
this.submitted = future;
future.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Removing routes {}, succeed", nlri);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Removing routes failed", throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri in project bgpcep by opendaylight.
the class BgpPeerUtilTest method isEndOfTableTest.
@Test
public void isEndOfTableTest() {
final Update ipv4EOT = new UpdateBuilder().build();
final MpUnreachNlri ipv6EOTnlri = new MpUnreachNlriBuilder().setAfi(IPV6_TABLE_KEY.getAfi()).setSafi(IPV6_TABLE_KEY.getSafi()).build();
final Update ipv6EOT = new UpdateBuilder().setAttributes(new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(ipv6EOTnlri).build()).build()).build();
assertTrue(BgpPeerUtil.isEndOfRib(ipv4EOT));
assertTrue(BgpPeerUtil.isEndOfRib(ipv6EOT));
final Update ipv4NonEOT = new UpdateBuilder().setNlri(Collections.singletonList(new NlriBuilder().setPrefix(new Ipv4Prefix("0.0.0.0/32")).build())).build();
final MpUnreachNlri ipv6NonEOTnlri = new MpUnreachNlriBuilder(ipv6EOTnlri).setWithdrawnRoutes(new WithdrawnRoutesBuilder().build()).build();
final Update ipv6NonEOT = new UpdateBuilder().setAttributes(new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(ipv6NonEOTnlri).build()).build()).build();
assertFalse(BgpPeerUtil.isEndOfRib(ipv4NonEOT));
assertFalse(BgpPeerUtil.isEndOfRib(ipv6NonEOT));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri in project bgpcep by opendaylight.
the class BGPUpdateMessageParser method withdrawAttributes.
private Attributes withdrawAttributes(final Attributes parsed, final BGPTreatAsWithdrawException withdrawCause) throws BGPDocumentedException {
final AttributesBuilder builder = new AttributesBuilder();
final MpReachNlri mpReachNlri = getMpReach(parsed);
if (mpReachNlri == null) {
// No MP_REACH attribute, just reuse MP_UNREACH if it is present.
final AttributesUnreach attrs2 = parsed.augmentation(AttributesUnreach.class);
if (attrs2 != null) {
builder.addAugmentation(attrs2);
}
return builder.build();
}
final MpUnreachNlri unreachNlri = getMpUnreach(parsed);
if (unreachNlri != null) {
final TablesKey reachKey = new TablesKey(mpReachNlri.getAfi(), mpReachNlri.getSafi());
final TablesKey unreachKey = new TablesKey(unreachNlri.getAfi(), unreachNlri.getSafi());
if (!reachKey.equals(unreachKey)) {
LOG.warn("Unexpected mismatch between MP_REACH ({}) and MP_UNREACH ({})", reachKey, unreachKey, withdrawCause);
throw new BGPDocumentedException(withdrawCause);
}
}
final MpUnreachNlri converted = this.nlriReg.convertMpReachToMpUnReach(mpReachNlri, unreachNlri).orElseThrow(() -> {
LOG.warn("Could not convert attributes {} to withdraw attributes", parsed, withdrawCause);
return new BGPDocumentedException(withdrawCause);
});
builder.addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(converted).build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri in project bgpcep by opendaylight.
the class RIBSupportTest method buildUpdate.
@Test
public void buildUpdate() {
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("10.0.0.2")).build()).build();
final Attributes attr = new AttributesBuilder().setCNextHop(nextHop).build();
final Collection<MapEntryNode> routes = new HashSet<>();
assertEquals(new UpdateBuilder().setAttributes(new AttributesBuilder().build()).build(), this.ribSupportTestImp.buildUpdate(routes, routes, attr));
routes.add(this.mapEntryNode);
final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setCNextHop(nextHop).setAdvertizedRoutes(new AdvertizedRoutesBuilder().build()).build();
final Attributes attMpR = new AttributesBuilder().addAugmentation(new AttributesReachBuilder().setMpReachNlri(mpReach).build()).build();
assertEquals(new UpdateBuilder().setAttributes(attMpR).build(), this.ribSupportTestImp.buildUpdate(routes, Collections.emptySet(), attr));
final MpUnreachNlri mpUnreach = new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().build()).build();
final Attributes attMpU = new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(mpUnreach).build()).build();
assertEquals(new UpdateBuilder().setAttributes(attMpU).build(), this.ribSupportTestImp.buildUpdate(Collections.emptySet(), routes, attr));
}
Aggregations