use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors in project bgpcep by opendaylight.
the class StateProviderImpl method storeOperationalState.
private synchronized void storeOperationalState(final BGPRibState bgpStateConsumer, final List<BGPPeerState> peerStats, final String ribId, final WriteTransaction wtx) {
final Global global = GlobalUtil.buildGlobal(bgpStateConsumer, this.bgpTableTypeRegistry);
final PeerGroups peerGroups = PeerGroupUtil.buildPeerGroups(peerStats);
final Neighbors neighbors = NeighborUtil.buildNeighbors(peerStats, this.bgpTableTypeRegistry);
InstanceIdentifier<Bgp> bgpIID = this.instanceIdentifiersCache.get(ribId);
if (bgpIID == null) {
final ProtocolKey protocolKey = new ProtocolKey(BGP.class, bgpStateConsumer.getInstanceIdentifier().getKey().getId().getValue());
final KeyedInstanceIdentifier<Protocol, ProtocolKey> protocolIId = this.networkInstanceIId.child(Protocols.class).child(Protocol.class, protocolKey);
bgpIID = protocolIId.augmentation(NetworkInstanceProtocol.class).child(Bgp.class);
this.instanceIdentifiersCache.put(ribId, bgpIID);
}
final Bgp bgp = new BgpBuilder().setGlobal(global).setNeighbors(neighbors).setPeerGroups(peerGroups).build();
wtx.put(LogicalDatastoreType.OPERATIONAL, bgpIID, bgp, WriteTransaction.CREATE_MISSING_PARENTS);
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors in project bgpcep by opendaylight.
the class StateProviderImplTest method testActiveStateProvider.
@Test
public void testActiveStateProvider() throws Exception {
doReturn(true).when(this.bgpRibState).isActive();
doReturn(true).when(this.bgpPeerState).isActive();
final StateProviderImpl stateProvider = new StateProviderImpl(getDataBroker(), 1, this.tableTypeRegistry, this.stateCollector, "global-bgp");
stateProvider.init();
final Global globalExpected = buildGlobalExpected(0);
this.bgpRibStates.add(this.bgpRibState);
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Global global = bgpRib.getGlobal();
assertEquals(globalExpected, global);
return bgpRib;
});
this.totalPathsCounter.increment();
this.totalPrefixesCounter.increment();
final Global globalExpected2 = buildGlobalExpected(1);
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Global global = bgpRib.getGlobal();
assertEquals(globalExpected2, global);
return bgpRib;
});
this.totalPathsCounter.decrement();
this.totalPrefixesCounter.decrement();
final Global globalExpected3 = buildGlobalExpected(0);
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Global global = bgpRib.getGlobal();
assertEquals(globalExpected3, global);
Assert.assertNull(bgpRib.getNeighbors());
Assert.assertNull(bgpRib.getPeerGroups());
return bgpRib;
});
this.bgpPeerStates.add(this.bgpPeerState);
final PeerGroup peerGroupExpected = buildGroupExpected();
this.totalPathsCounter.increment();
this.totalPrefixesCounter.increment();
final AfiSafis expectedAfiSafis = buildAfiSafis();
final ErrorHandling expectedErrorHandling = buildErrorHandling();
final GracefulRestart expectedGracefulRestart = buildGracefulRestart();
final Transport expectedTransport = buildTransport();
final Timers expectedTimers = buildTimers();
final BgpNeighborStateAugmentation expectedBgpNeighborState = buildBgpNeighborStateAugmentation();
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Neighbors neighbors = bgpRib.getNeighbors();
Assert.assertNotNull(neighbors);
assertEquals(peerGroupExpected, bgpRib.getPeerGroups().getPeerGroup().get(0));
final Neighbor neighborResult = neighbors.getNeighbor().get(0);
assertEquals(this.neighborAddress, neighborResult.getNeighborAddress());
assertEquals(expectedAfiSafis, neighborResult.getAfiSafis());
assertEquals(expectedErrorHandling, neighborResult.getErrorHandling());
assertEquals(expectedGracefulRestart, neighborResult.getGracefulRestart());
assertEquals(expectedTransport, neighborResult.getTransport());
assertEquals(expectedTimers, neighborResult.getTimers());
final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.State stateResult = neighborResult.getState();
assertEquals(expectedBgpNeighborState, stateResult.getAugmentation(BgpNeighborStateAugmentation.class));
assertEquals(BgpNeighborState.SessionState.ESTABLISHED, stateResult.getAugmentation(NeighborStateAugmentation.class).getSessionState());
final List<Class<? extends BgpCapability>> supportedCapabilitiesResult = stateResult.getAugmentation(NeighborStateAugmentation.class).getSupportedCapabilities();
Assert.assertTrue(supportedCapabilitiesResult.containsAll(this.supportedCap));
return bgpRib;
});
this.bgpRibStates.clear();
checkNotPresentOperational(getDataBroker(), this.bgpInstanceIdentifier);
stateProvider.close();
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors in project netvirt by opendaylight.
the class BgpConfigurationManager method replayNbrConfig.
private static boolean replayNbrConfig(List<Neighbors> neighbors, BgpRouter br) {
if (neighbors == null || neighbors.isEmpty()) {
LOG.error("Replaying nbr configuration, received NULL list ");
return true;
}
List<ReplayNbr> replayNbrList = new ArrayList<>();
for (Neighbors nbr : neighbors) {
if (nbr != null) {
replayNbrList.add(new ReplayNbr(nbr, true));
}
}
final int numberOfNbrRetries = 3;
RetryOnException nbrRetry = new RetryOnException(numberOfNbrRetries);
do {
for (ReplayNbr replayNbr : replayNbrList) {
if (!replayNbr.isShouldRetry()) {
continue;
}
boolean replayDone = false;
LOG.debug("Replaying addNbr {}", replayNbr.getNbr().getAddress().getValue());
replayDone = false;
try {
final String md5password = extractMd5Secret(replayNbr.getNbr());
br.addNeighbor(replayNbr.getNbr().getAddress().getValue(), replayNbr.getNbr().getRemoteAs().longValue(), md5password);
UpdateSource us = replayNbr.getNbr().getUpdateSource();
if (us != null) {
LOG.debug("Replaying updatesource along with nbr: {} US-ip: {} to peer {}", replayNbr.getNbr().getAddress().getValue(), us.getSourceIp().getValue(), us.getPeerIp().getValue());
br.addUpdateSource(us.getPeerIp().getValue(), us.getSourceIp().getValue());
}
replayDone = true;
} catch (TException | BgpRouterException eNbr) {
LOG.debug("Replaying addNbr {}, exception: ", replayNbr.getNbr().getAddress().getValue(), eNbr);
}
boolean replaySuccess = true;
replaySuccess = replaySuccess && replayDone;
LOG.debug("Replay addNbr {} successful", replayNbr.getNbr().getAddress().getValue());
// Update Source handling
UpdateSource us = replayNbr.getNbr().getUpdateSource();
if (replayDone == false && us != null) {
LOG.debug("Replaying updatesource {} to peer {}", us.getSourceIp().getValue(), us.getPeerIp().getValue());
replayDone = false;
try {
br.addUpdateSource(us.getPeerIp().getValue(), us.getSourceIp().getValue());
replayDone = true;
} catch (TException | BgpRouterException eUs) {
LOG.debug("Replaying UpdateSource for Nbr {}, exception:", replayNbr.getNbr().getAddress().getValue(), eUs);
}
LOG.debug("Replay updatesource {} successful", us.getSourceIp().getValue());
replaySuccess = replaySuccess && replayDone;
}
// Ebgp Multihope
EbgpMultihop en = replayNbr.getNbr().getEbgpMultihop();
if (en != null) {
replayDone = false;
try {
br.addEbgpMultihop(en.getPeerIp().getValue(), en.getNhops().intValue());
replayDone = true;
} catch (TException | BgpRouterException eEbgpMhop) {
LOG.debug("Replaying EbgpMultihop for Nbr {}, exception: ", replayNbr.getNbr().getAddress().getValue(), eEbgpMhop);
}
replaySuccess = replaySuccess && replayDone;
}
// afs
List<AddressFamilies> afs = replayNbr.getNbr().getAddressFamilies();
if (afs != null) {
for (AddressFamilies af : afs) {
af_afi afi = af_afi.findByValue(af.getAfi().intValue());
af_safi safi = af_safi.findByValue(af.getSafi().intValue());
replayDone = false;
try {
br.addAddressFamily(af.getPeerIp().getValue(), afi, safi);
replayDone = true;
} catch (TException | BgpRouterException eAFs) {
LOG.debug("Replaying AddressFamily for Nbr {}, exception:", replayNbr.getNbr().getAddress().getValue(), eAFs);
}
replaySuccess = replaySuccess && replayDone;
}
}
// replay is success --> no need to replay this nbr in next iteration.
replayNbr.setShouldRetry(replaySuccess ? false : true);
}
} while (nbrRetry.decrementAndRetry());
boolean replaySuccess = true;
for (ReplayNbr replayNbr : replayNbrList) {
replaySuccess = replaySuccess && !replayNbr.isShouldRetry();
}
return replaySuccess;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors in project netvirt by opendaylight.
the class BgpConfigurationManager method replay.
@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized boolean replay() throws InterruptedException, TimeoutException, ExecutionException {
boolean replaySucceded = true;
String host = getConfigHost();
int port = getConfigPort();
LOG.error("connecting to bgp host {} ", host);
boolean res = bgpRouter.connect(host, port);
if (!res) {
LOG.error("Cannot connect to BGP config server at {}:{}{}", host, port, config != null ? "; Configuration Replay aborted" : "");
return replaySucceded;
}
config = getConfig();
if (config == null) {
LOG.error("bgp config is empty nothing to push to bgp");
return replaySucceded;
}
BgpRouter br = bgpRouter;
AsId asId = config.getAsId();
if (asId == null) {
LOG.error("bgp as-id is null");
return replaySucceded;
}
long asNum = asId.getLocalAs();
IpAddress routerId = asId.getRouterId();
String rid = routerId == null ? "" : new String(routerId.getValue());
int stalepathTime = (int) getStalePathtime(RESTART_DEFAULT_GR, config.getAsId());
boolean announceFbit = true;
boolean replayDone = false;
final int numberOfStartBgpRetries = 3;
RetryOnException startBgpRetry = new RetryOnException(numberOfStartBgpRetries);
do {
try {
LOG.debug("Replaying BGPConfig ");
br.startBgp(asNum, rid, stalepathTime, announceFbit);
LOG.debug("Replay BGPConfig successful");
replayDone = true;
break;
} catch (BgpRouterException bre) {
if (bre.getErrorCode() == BgpRouterException.BGP_ERR_ACTIVE) {
LOG.debug("Starting the routesync for exception", bre);
startBgpRetry.errorOccured();
if (!startBgpRetry.shouldRetry()) {
LOG.debug("starting route sync for BgpRouter exception");
doRouteSync();
}
} else {
LOG.error("Replay: startBgp() received exception error {} : ", bre.getErrorCode(), bre);
startBgpRetry.errorOccured();
}
} catch (TApplicationException tae) {
if (tae.getType() == BgpRouterException.BGP_ERR_ACTIVE) {
LOG.debug("Starting the routesync for exception", tae);
startBgpRetry.errorOccured();
if (!startBgpRetry.shouldRetry()) {
LOG.debug("starting route sync for Thrift BGP_ERR_ACTIVE exception");
doRouteSync();
}
} else if (tae.getType() == BgpRouterException.BGP_ERR_COMMON_FAILURE) {
LOG.debug("Starting the routesync for AS-ID started exception", tae);
startBgpRetry.errorOccured();
if (!startBgpRetry.shouldRetry()) {
LOG.debug("starting route sync for Thrift BGP_ERR_COMMON_FAILURE exception");
doRouteSync();
}
} else {
LOG.error("Replay: startBgp() received exception type {}: ", tae.getType(), tae);
startBgpRetry.errorOccured();
}
} catch (Exception e) {
// not unusual. We may have restarted & BGP is already on
LOG.error("Replay:startBgp() received exception: ", e);
startBgpRetry.errorOccured();
}
} while (startBgpRetry.shouldRetry());
replaySucceded = replayDone;
startBgpCountersTask();
startBgpAlarmsTask();
/*
* commenting this due to a bug with QBGP. Will uncomment once QBGP fix is done.
* This wont have any functional impacts
*/
// try {
// br.delayEOR(delayEorSeconds);
// } catch (TException | BgpRouterException e) {
// LOG.error("Replay: delayEOR() number of seconds to wait for EOR from ODL:", e);
// }
List<Neighbors> neighbors = config.getNeighbors();
if (neighbors != null) {
LOG.error("configuring existing Neighbors present for replay total neighbors {}", neighbors.size());
boolean neighborConfigReplayResult = replayNbrConfig(neighbors, br);
if (neighborConfigReplayResult == false) {
replaySucceded = false;
}
} else {
LOG.error("no Neighbors present for replay config ");
}
Logging logging = config.getLogging();
if (logging != null) {
try {
br.setLogging(logging.getFile(), logging.getLevel());
} catch (TException | BgpRouterException e) {
LOG.error("Replay:setLogging() received exception", e);
}
}
GracefulRestart gracefulRestart = config.getGracefulRestart();
if (gracefulRestart != null) {
try {
br.addGracefulRestart(gracefulRestart.getStalepathTime().intValue());
} catch (TException | BgpRouterException e) {
LOG.error("Replay:addGr() received exception", e);
}
}
List<Vrfs> vrfs = config.getVrfs();
if (vrfs == null) {
vrfs = new ArrayList<>();
}
for (Vrfs vrf : vrfs) {
for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf()) {
try {
br.addVrf(BgpUtil.getLayerType(adf), vrf.getRd(), vrf.getImportRts(), vrf.getExportRts());
} catch (TException | BgpRouterException e) {
LOG.error("Replay:addVrf() received exception", e);
}
}
}
List<Networks> ln = config.getNetworks();
if (ln != null) {
for (Networks net : ln) {
String rd = net.getRd();
String pfxlen = net.getPrefixLen();
String nh = net.getNexthop().getValue();
Long label = net.getLabel();
int lbl = label == null ? 0 : label.intValue();
int l3vni = net.getL3vni() == null ? 0 : net.getL3vni().intValue();
int l2vni = net.getL2vni() == null ? 0 : net.getL2vni().intValue();
if (rd == null && lbl > 0) {
// LU prefix is being deleted.
rd = Integer.toString(lbl);
}
BgpControlPlaneType protocolType = net.getBgpControlPlaneType();
int ethernetTag = net.getEthtag().intValue();
String esi = net.getEsi();
String macaddress = net.getMacaddress();
EncapType encapType = net.getEncapType();
String routerMac = net.getRoutermac();
try {
br.addPrefix(rd, pfxlen, nh, lbl, l3vni, l2vni, BgpUtil.convertToThriftProtocolType(protocolType), ethernetTag, esi, macaddress, BgpUtil.convertToThriftEncapType(encapType), routerMac);
} catch (TException | BgpRouterException e) {
LOG.error("Replay:addPfx() received exception", e);
}
}
}
List<Multipath> multipaths = config.getMultipath();
if (multipaths != null) {
for (Multipath multipath : multipaths) {
if (multipath != null) {
af_afi afi = af_afi.findByValue(multipath.getAfi().intValue());
af_safi safi = af_safi.findByValue(multipath.getSafi().intValue());
try {
if (multipath.isMultipathEnabled()) {
br.enableMultipath(afi, safi);
} else {
br.disableMultipath(afi, safi);
}
} catch (TException | BgpRouterException e) {
LOG.info("Replay:multipaths() received exception", e);
}
}
}
}
List<VrfMaxpath> vrfMaxpaths = config.getVrfMaxpath();
if (vrfMaxpaths != null) {
for (VrfMaxpath vrfMaxpath : vrfMaxpaths) {
try {
br.multipaths(vrfMaxpath.getRd(), vrfMaxpath.getMaxpaths());
} catch (TException | BgpRouterException e) {
LOG.info("Replay:vrfMaxPath() received exception", e);
}
}
}
// send End of Rib Marker to Qthriftd.
final int numberOfEORRetries = 3;
replayDone = false;
RetryOnException eorRetry = new RetryOnException(numberOfEORRetries);
do {
try {
br.sendEOR();
LOG.debug("Replay sendEOR {} successful");
replayDone = true;
break;
} catch (Exception e) {
eorRetry.errorOccured();
LOG.error("Replay:sedEOR() received exception:", e);
}
} while (eorRetry.shouldRetry());
return replaySucceded && replayDone;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors in project netvirt by opendaylight.
the class BgpConfigurationManager method extractMd5Secret.
private static String extractMd5Secret(final Neighbors val) {
String md5Secret = null;
TcpSecurityOption tcpSecOpt = val.getTcpSecurityOption();
if (tcpSecOpt != null) {
if (tcpSecOpt instanceof TcpMd5SignatureOption) {
md5Secret = ((TcpMd5SignatureOption) tcpSecOpt).getTcpMd5SignaturePassword().getValue();
} else {
// unknown TcpSecurityOption
LOG.debug("neighbors Ignored unknown tcp-security-option of peer {}", val.getAddress().getValue());
}
}
return md5Secret;
}
Aggregations