use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class EffectiveRibInWriter method writeRoute.
private void writeRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport<?, ?> ribSupport, final YangInstanceIdentifier routePath, final Optional<NormalizedNode> routeBefore, final NormalizedNode routeAfter, final boolean longLivedStale) {
final TablesKey tablesKey = ribSupport.getTablesKey();
CountersUtil.increment(this.prefixesReceived.get(tablesKey), tablesKey);
// Lookup per-table attributes from RIBSupport
final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(routeAfter, ribSupport.routeAttributesIdentifier()).orElse(null);
final Attributes routeAttrs = ribSupport.attributeFromContainerNode(advertisedAttrs);
final Optional<Attributes> optEffAtt;
// considered as received with LLGR_STALE from peer which is not true.
if (longLivedStale) {
// LLGR procedures are in effect. If the route is tagged with NO_LLGR, it needs to be removed.
final List<Communities> effCommunities = routeAttrs.getCommunities();
if (effCommunities != null && effCommunities.contains(CommunityUtil.NO_LLGR)) {
deleteRoute(tx, ribSupport, routePath, routeBefore.orElse(null));
return;
}
optEffAtt = Optional.of(wrapLongLivedStale(routeAttrs));
} else {
optEffAtt = ribPolicies.applyImportPolicies(peerImportParameters, routeAttrs, verifyNotNull(tableTypeRegistry.getAfiSafiType(ribSupport.getTablesKey())));
}
if (!optEffAtt.isPresent()) {
deleteRoute(tx, ribSupport, routePath, routeBefore.orElse(null));
return;
}
handleRouteTarget(ModificationType.WRITE, ribSupport, routePath, routeAfter);
tx.put(LogicalDatastoreType.OPERATIONAL, routePath, routeAfter);
CountersUtil.increment(this.prefixesInstalled.get(tablesKey), tablesKey);
final Attributes attToStore = optEffAtt.get();
if (!attToStore.equals(routeAttrs)) {
final YangInstanceIdentifier attPath = routePath.node(ribSupport.routeAttributesIdentifier());
final ContainerNode finalAttribute = ribSupport.attributeToContainerNode(attPath, attToStore);
tx.put(LogicalDatastoreType.OPERATIONAL, attPath, finalAttribute);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class AbstractAddPathTest method configurePeer.
static BGPPeer configurePeer(final BGPTableTypeRegistryConsumer tableRegistry, final Ipv4AddressNoZone peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry, final Set<TablesKey> afiSafiAdvertised, final Set<TablesKey> gracefulAfiSafiAdvertised, final Map<TablesKey, Integer> llGracefulTimersAdvertised, final BgpPeer peer) {
final IpAddressNoZone ipAddress = new IpAddressNoZone(peerAddress);
final BGPPeer bgpPeer = new BGPPeer(tableRegistry, new IpAddressNoZone(peerAddress), null, ribImpl, peerRole, null, null, null, afiSafiAdvertised, gracefulAfiSafiAdvertised, llGracefulTimersAdvertised, peer);
final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
bgpPeerRegistry.addPeer(ipAddress, bgpPeer, new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID), AS_NUMBER, tlvs));
bgpPeer.instantiateServiceInstance();
return bgpPeer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class BgpPeerRpcTest method setUp.
@Before
public void setUp() throws InterruptedException, ExecutionException {
this.rpc = new BgpPeerRpc(this.peerRpcs, this.session, Collections.singleton(new TablesKey(Ipv4AddressFamily.class, SubsequentAddressFamily.class)));
final ChannelOutputLimiter limiter = new ChannelOutputLimiter(this.session);
doReturn(limiter).when(this.session).getLimiter();
doReturn(this.future).when(this.session).writeAndFlush(any(Notification.class));
doReturn(true).when(this.future).isSuccess();
doAnswer(invocation -> {
GenericFutureListener<ChannelFuture> listener = invocation.getArgument(0);
listener.operationComplete(this.future);
return null;
}).when(this.future).addListener(any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class SynchronizationAndExceptionTest method testUseCase1.
@Test
public void testUseCase1() {
final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy());
final RIBImpl ribImpl = new RIBImpl(this.tableRegistry, new RibId(RIB_ID), AS_NUMBER, new BgpId(RIB_ID), this.ribExtension, this.serverDispatcher, this.codecsRegistry, this.domBroker, this.policies, ImmutableList.of(this.ipv4tt), pathTables);
ribImpl.instantiateServiceInstance();
final BGPPeer bgpPeer = AbstractAddPathTest.configurePeer(this.tableRegistry, neighbor.getIpv4AddressNoZone(), ribImpl, null, PeerRole.Ibgp, this.serverRegistry, AFI_SAFIS_ADVERTIZED, Collections.emptySet());
bgpPeer.instantiateServiceInstance();
final BGPSessionImpl bgpSession = new BGPSessionImpl(bgpPeer, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer().toJava(), null);
bgpSession.setChannelExtMsgCoder(this.classicOpen);
bgpPeer.onSessionUp(bgpSession);
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 wrongMessage = new UpdateBuilder();
wrongMessage.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();
wrongMessage.setAttributes(ab.setOrigin(origin).setAsPath(asPath).setCNextHop(nextHop).build());
final UpdateBuilder correct = new UpdateBuilder(wrongMessage.build());
correct.setAttributes(ab.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build()).build());
bgpSession.handleMessage(correct.build());
verify(this.tx, times(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
bgpSession.handleMessage(new UpdateBuilder().build());
verify(this.tx, times(3)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
verify(this.tx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(TABLE_PATH), eq(ImmutableNodes.leafNode(UPTODATE_NID, Boolean.TRUE)));
verify(this.tx, times(0)).delete(eq(LogicalDatastoreType.OPERATIONAL), eq(PEER_PATH));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey in project bgpcep by opendaylight.
the class GracefulRestartUtilTest method getGracefulCapabilityTest.
@Test
public void getGracefulCapabilityTest() {
final Map<TablesKey, Boolean> gracefulMap = new HashMap<>();
gracefulMap.put(IPV4_KEY, true);
gracefulMap.put(IPV6_KEY, false);
CParameters capability = GracefulRestartUtil.getGracefulCapability(gracefulMap, RESTART_TIME, RESTARTING);
final CParameters1 params = capability.augmentation(CParameters1.class);
assertNotNull(params);
final GracefulRestartCapability gracefulCapability = params.getGracefulRestartCapability();
assertNotNull(gracefulCapability);
assertTrue(gracefulCapability.getRestartFlags().getRestartState());
assertEquals(RESTART_TIME, gracefulCapability.getRestartTime().intValue());
final var tables = gracefulCapability.getTables();
assertNotNull(tables);
assertEquals(2, tables.size());
tables.values().forEach(table -> {
assertTrue(isSameKey(IPV4_KEY, table.key()) && table.getAfiFlags().getForwardingState() || isSameKey(IPV6_KEY, table.key()) && !table.getAfiFlags().getForwardingState());
});
}
Aggregations