use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev171207.server.config.Server in project bgpcep by opendaylight.
the class Stateful07TopologySessionListenerTest method testOnServerSessionManagerRestartAndSessionRecovery.
@Test
public void testOnServerSessionManagerRestartAndSessionRecovery() throws Exception {
// close server session manager first
stopSessionManager();
assertFalse(this.session.isClosed());
this.listener.onSessionUp(this.session);
// verify the session was NOT added to topology
checkNotPresentOperational(getDataBroker(), TOPO_IID);
// verify the session is closed due to server session manager is closed
assertTrue(this.session.isClosed());
// send request
final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
final AddLspOutput output = futureOutput.get().getResult();
// deal with unsent request after session down
assertEquals(FailureType.Unsent, output.getFailure());
// PCC client is not there
checkNotPresentOperational(getDataBroker(), this.pathComputationClientIId);
// reset received message queue
this.receivedMsgs.clear();
// now we restart the session manager
startSessionManager();
// try to start the session again
// notice since the session was terminated before, it is not usable anymore.
// we need to get a new session instance. the new session will have the same local / remote preference
this.session = getPCEPSession(getLocalPref(), getRemotePref());
assertFalse(this.session.isClosed());
this.listener.onSessionUp(this.session);
assertFalse(this.session.isClosed());
// create node
this.topologyRpcs.addLsp(createAddLspInput());
final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final long srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true, this.testAddress, this.testAddress, this.testAddress, Optional.absent());
final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
this.listener.onMessage(this.session, pcRpt);
readDataOperational(getDataBroker(), TOPO_IID, topology -> {
assertEquals(1, topology.getNode().size());
return topology;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev171207.server.config.Server in project bgpcep by opendaylight.
the class Stateful07TopologySessionListenerTest method testOnServerSessionManagerDown.
/**
* All the pcep session registration should be closed when the session manager is closed.
*/
@Test
public void testOnServerSessionManagerDown() throws InterruptedException, ExecutionException, TransactionCommitFailedException {
this.listener.onSessionUp(this.session);
// the session should not be closed when session manager is up
assertFalse(this.session.isClosed());
// send request
final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
stopSessionManager();
final AddLspOutput output = futureOutput.get().getResult();
// deal with unsent request after session down
assertEquals(FailureType.Unsent, output.getFailure());
// verify the session is closed after server session manager is closed
assertTrue(this.session.isClosed());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev171207.server.config.Server in project bgpcep by opendaylight.
the class ServerSessionManager method takeNodeState.
synchronized TopologyNodeState takeNodeState(final InetAddress address, final TopologySessionListener sessionListener, final boolean retrieveNode) {
final NodeId id = createNodeId(address);
if (this.isClosed.get()) {
LOG.error("Server Session Manager is closed. Unable to create topology node {} with listener {}", id, sessionListener);
return null;
}
LOG.debug("Node {} requested by listener {}", id, sessionListener);
TopologyNodeState ret = this.state.get(id);
if (ret == null) {
ret = new TopologyNodeState(this.dependenciesProvider.getDataBroker(), this.topology, id, DEFAULT_HOLD_STATE_NANOS);
LOG.debug("Created topology node {} for id {} at {}", ret, id, ret.getNodeId());
this.state.put(id, ret);
}
// if another listener requests the same session, close it
final TopologySessionListener existingSessionListener = this.nodes.get(id);
if (existingSessionListener != null && !sessionListener.equals(existingSessionListener)) {
LOG.error("New session listener {} is in conflict with existing session listener {} on node {}," + " closing the existing one.", existingSessionListener, sessionListener, id);
existingSessionListener.close();
}
ret.taken(retrieveNode);
this.nodes.put(id, sessionListener);
LOG.debug("Node {} bound to listener {}", id, sessionListener);
return ret;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev171207.server.config.Server 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.opendaylight.params.xml.ns.yang.bmp.monitor.config.rev171207.server.config.Server in project netvirt by opendaylight.
the class Cache method doExecute.
@SuppressWarnings("resource")
@Override
protected Object doExecute() {
boolean listVrfs = false;
boolean listNets = false;
PrintStream ps = session.getConsole();
if (action != null) {
return usage();
}
PrintStream fileStream = null;
if (ofile != null) {
try {
fileStream = new PrintStream(ofile);
ps = fileStream;
} catch (FileNotFoundException e) {
session.getConsole().println("error: cannot create file " + ofile + "; exception: " + e);
return null;
}
}
if (list != null) {
for (String item : list) {
switch(item) {
case "vrfs":
listVrfs = true;
break;
case "networks":
listNets = true;
break;
default:
session.getConsole().println("error: unknown value for " + LST + ": " + item);
if (fileStream != null) {
fileStream.close();
}
return null;
}
}
}
// we'd normally read this directly from 'config' but
// legacy behaviour forces to check for a connection
// that's initiated by default at startup without
// writing to config.
String configHost = bgpManager.getConfigHost();
int configPort = bgpManager.getConfigPort();
ps.printf("%nConfiguration Server%n\t%s %s%n\t%s %d%n", HTSTR, configHost, PTSTR, configPort);
Bgp config = bgpManager.getConfig();
if (config == null) {
if (fileStream != null) {
fileStream.close();
}
return null;
}
AsId asId = config.getAsId();
if (asId != null) {
int asNum = asId.getLocalAs().intValue();
IpAddress routerId = asId.getRouterId();
Long spt = asId.getStalepathTime();
Boolean afb = asId.isAnnounceFbit();
String rid = routerId == null ? "<n/a>" : new String(routerId.getValue());
// F-bit is always set to ON (hardcoded), in SDN even though the controller is down
// forwarding state shall be retained.
String bit = "ON";
GracefulRestart gracefulRestart = config.getGracefulRestart();
if (gracefulRestart != null) {
spt = gracefulRestart.getStalepathTime();
}
ps.printf("%nBGP Router%n");
ps.printf("\t%-15s %d%n\t%-15s %s%n\t%-15s %s%n\t%-15s %s%n", ASSTR, asNum, RISTR, rid, SPSTR, spt == null || spt == 0 ? "default" : spt.toString(), FBSTR, bit);
}
Logging logging = config.getLogging();
if (logging != null) {
ps.printf("\t%-15s %s%n\t%-15s %s%n", LFSTR, logging.getFile(), LLSTR, logging.getLevel());
}
List<Neighbors> neighbors = config.getNeighbors();
if (neighbors != null) {
ps.printf("%nNeighbors%n");
for (Neighbors nbr : neighbors) {
ps.printf("\t%s%n\t\t%-16s %d%n", nbr.getAddress().getValue(), ASSTR, nbr.getRemoteAs().intValue());
EbgpMultihop en = nbr.getEbgpMultihop();
if (en != null) {
ps.printf("\t\t%-16s %d%n", EBSTR, en.getNhops().intValue());
}
UpdateSource us = nbr.getUpdateSource();
if (us != null) {
ps.printf("\t\t%-16s %s%n", USSTR, us.getSourceIp().getValue());
}
ps.printf("\t\t%-16s IPv4-Labeled-VPN", AFSTR);
List<AddressFamilies> afs = nbr.getAddressFamilies();
if (afs != null) {
for (AddressFamilies af : afs) {
// Should not print "unknown" in vpnv4 case
if (!(af.getSafi().intValue() == 5 && af.getAfi().intValue() == 1)) {
if (af.getSafi().intValue() == 4 && af.getAfi().intValue() == 1) {
ps.printf(" %s", "IPv4-Labeled-Unicast");
} else if (af.getSafi().intValue() == 5 && af.getAfi().intValue() == 2) {
ps.printf(" %s", "IPv6-Labeled-VPN");
} else if (af.getSafi().intValue() == 6) {
ps.printf(" %s", "Ethernet-VPN");
} else {
ps.printf(" %s", "Unknown");
}
}
}
}
ps.printf("%n");
}
}
if (listVrfs) {
List<Vrfs> vrfs = config.getVrfs();
if (vrfs != null) {
ps.printf("%nVRFs%n");
for (Vrfs vrf : vrfs) {
ps.printf("\t%s%n", vrf.getRd());
ps.printf("\t\t%s ", IRSTR);
for (String rt : vrf.getImportRts()) {
ps.printf("%s ", rt);
}
ps.printf("%n\t\t%s ", ERSTR);
for (String rt : vrf.getExportRts()) {
ps.printf("%s ", rt);
}
for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf()) {
ps.printf("%n\t\tafi %d safi %d", adf.getAfi(), adf.getSafi());
}
ps.printf("%n");
}
}
}
if (listNets) {
List<Networks> ln = config.getNetworks();
if (ln != null) {
ps.printf("%nNetworks%n");
for (Networks net : ln) {
String rd = net.getRd();
String pfxlen = net.getPrefixLen();
String nh = net.getNexthop().getValue();
int label = net.getLabel().intValue();
ps.printf("\t%s%n\t\t%-7s %s%n\t\t%-7s %s%n\t\t%-7s %d%n", pfxlen, RDSTR, rd, NHSTR, nh, LBSTR, label);
}
}
}
List<Multipath> mp = config.getMultipath();
List<VrfMaxpath> vrfm = config.getVrfMaxpath();
if (mp != null) {
ps.printf("%nMultipath%n");
for (Multipath multipath : mp) {
int afi = multipath.getAfi().intValue();
int safi = multipath.getSafi().intValue();
Boolean enabled = multipath.isMultipathEnabled();
if (enabled) {
if (afi == 1 && safi == 5) {
ps.printf("\t%-16s %s%n%n", AFSTR, "vpnv4");
} else if (afi == 2 && safi == 5) {
ps.printf("\t%-16s %s%n%n", AFSTR, "vpnv6");
} else if (afi == 3 && safi == 6) {
ps.printf("\t%-16s %s%n%n", AFSTR, "evpn");
} else {
ps.printf("\t%-16s %s%n%n", AFSTR, "Unknown");
}
if (vrfm != null) {
ps.printf("\t%-16s %s%n", RDSTR, MPSTR);
for (VrfMaxpath vrfMaxpath : vrfm) {
String rd = vrfMaxpath.getRd();
int maxpath = vrfMaxpath.getMaxpaths();
ps.printf("\t%-16s %d%n", rd, maxpath);
}
}
}
}
}
if (fileStream != null) {
fileStream.close();
}
return null;
}
Aggregations