use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer 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.bmp.monitor.rev200120.peers.Peer 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.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.
the class OpenConfigMappingUtilTest method getRevisedErrorHandlingTest.
@Test
public void getRevisedErrorHandlingTest() {
final NeighborBuilder neighbor = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS);
final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName("foo");
final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.error.handling.ConfigBuilder errorHandlingConfig = new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.error.handling.ConfigBuilder();
// error handling not set -> null
assertNull(OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
// error handling for peer group disabled, neighbor not set -> null
peerGroup.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(false).build()).build());
assertNull(OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
// error handling for peer group enabled, neighbor not set, Igp -> error handling for internal peer
peerGroup.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(true).build()).build());
assertEquals(RevisedErrorHandlingSupportImpl.forInternalPeer(), OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
// error handling for peer group enabled, neighbor disabled -> null
neighbor.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(false).build()).build());
assertNull(OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
// error handling for peer group enabled, neighbor enabled, Igb -> error handling for internal peer
neighbor.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(true).build()).build());
assertEquals(RevisedErrorHandlingSupportImpl.forInternalPeer(), OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ibgp, peerGroup.build(), neighbor.build()));
// error handling for peer group enabled, neighbor enabled, Egb -> error handling for external peer
neighbor.setErrorHandling(new ErrorHandlingBuilder().setConfig(errorHandlingConfig.setTreatAsWithdraw(true).build()).build());
assertEquals(RevisedErrorHandlingSupportImpl.forExternalPeer(), OpenConfigMappingUtil.getRevisedErrorHandling(PeerRole.Ebgp, peerGroup.build(), neighbor.build()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.
the class OpenConfigMappingUtilTest method getGracefulRestartTimerTest.
@Test
public void getGracefulRestartTimerTest() {
final int neighborTimer = 5;
final int peerGroupTimer = 10;
Neighbor neighbor = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS).setGracefulRestart(new GracefulRestartBuilder().setConfig(createGracefulConfig(Uint16.valueOf(neighborTimer))).build()).build();
PeerGroup peerGroup = new PeerGroupBuilder().setPeerGroupName("foo").setGracefulRestart(new GracefulRestartBuilder().setConfig(createGracefulConfig(Uint16.valueOf(peerGroupTimer))).build()).build();
// both timers present, pick peer group one
int timer = OpenConfigMappingUtil.getGracefulRestartTimer(neighbor, peerGroup, HOLDTIMER);
assertEquals(peerGroupTimer, timer);
// peer group missing graceful restart, use neighbor timer
timer = OpenConfigMappingUtil.getGracefulRestartTimer(neighbor, EMPTY_PEERGROUP, HOLDTIMER);
assertEquals(neighborTimer, timer);
// graceful restart enabled but timer not set, use hold time
peerGroup = new PeerGroupBuilder().setPeerGroupName("bar").setGracefulRestart(new GracefulRestartBuilder().setConfig(createGracefulConfig(null)).build()).build();
timer = OpenConfigMappingUtil.getGracefulRestartTimer(EMPTY_NEIGHBOR, peerGroup, HOLDTIMER);
assertEquals(HOLDTIMER, timer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testDuplicatePeersLowerAs.
@Test
public void testDuplicatePeersLowerAs() throws Exception {
final AsNumber as2 = new AsNumber(Uint32.valueOf(3));
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
try {
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.CEASE, e.getError());
return;
}
fail("Same peer cannot be connected twice");
}
Aggregations