private static final String PFX = "--prefix";
private static final String NH = "--nexthop";
private static final String LB = "--label";
+ private static final String AFI = "--afi";
static final Logger LOGGER = LoggerFactory.getLogger(Network.class);
@Argument(name = "add|del", description = "The desired operation",
required = false, multiValued = false)
private String lbl = null;
+ @Option(name = AFI, aliases = {"-a"},
+ description = "Address Family",
+ required = false, multiValued = false)
+ private String afi = "1";
+
private RouteOrigin staticOrigin = RouteOrigin.STATIC;
private Object usage() {
session.getConsole().println(
"usage: bgp-network [" + RD + " rd] [" + PFX + " prefix/len] ["
- + NH + " nexthop] [" + LB + " label] <add|del>");
+ + NH + " nexthop] [" + LB + " label] ["
+ + AFI + " afi] <add|del>");
return null;
}
} else {
label = Integer.valueOf(lbl);
}
- } else if (rd == null) {
- session.getConsole().println("error: " + RD + " is needed");
+ }
+ if (!Commands.isValid(session.getConsole(), afi, Commands.Validators.AFI, AFI)) {
+ session.getConsole().println("error: " + AFI + " must be 1 (IPv4) or 2 (IPv6). Default is 1");
return null;
}
LOGGER.info("ADD: Adding Fib entry rd {} prefix {} nexthop {} label {}", rd, pfx, nh, label);
return null;
}
if (nh != null || lbl != null) {
- session.getConsole().println("note: some option(s) not needed; ignored");
+ session.getConsole().println("note: some option(s) not needed as " + NH + " and/or " + LB
+ + "; will be ignored");
+ }
+ if (!Commands.isValid(session.getConsole(), afi, Commands.Validators.AFI, AFI)) {
+ session.getConsole().println("error: " + AFI + " must be 1 (IPv4) or 2 (IPv6). Default is 1");
+ return null;
}
LOGGER.info("REMOVE: Removing Fib entry rd {} prefix {}", rd, pfx);
bm.deletePrefix(rd, pfx);
package org.opendaylight.netvirt.bgpmanager.oam;
-import static org.opendaylight.netvirt.bgpmanager.oam.BgpCounters.parseIpBgpVpnv4AllSummary;
-import static org.opendaylight.netvirt.bgpmanager.oam.BgpCounters.resetFile;
-
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
List<Neighbors> nbrList = null;
try {
LOG.debug("Fetching neighbor status' from BGP");
- resetFile("cmd_ip_bgp_vpnv4_all_summary.txt");
+ BgpCounters.resetFile(BgpCounters.BGP_VPNV4_SUMMARY_FILE);
+ BgpCounters.resetFile(BgpCounters.BGP_VPNV6_SUMMARY_FILE);
neighborStatusMap.clear();
if (bgpMgr != null && bgpMgr.getBgpCounters() != null) {
- bgpMgr.getBgpCounters().fetchCmdOutputs("cmd_ip_bgp_vpnv4_all_summary.txt",
+ bgpMgr.getBgpCounters().fetchCmdOutputs(BgpCounters.BGP_VPNV4_SUMMARY_FILE,
"show ip bgp vpnv4 all summary");
if (bgpMgr.getConfig() != null) {
nbrList = bgpMgr.getConfig().getNeighbors();
}
- parseIpBgpVpnv4AllSummary(neighborStatusMap);
+ BgpCounters.parseIpBgpVpnv4AllSummary(neighborStatusMap);
+
+ bgpMgr.getBgpCounters().fetchCmdOutputs(BgpCounters.BGP_VPNV6_SUMMARY_FILE,
+ "show ip bgp vpnv6 all summary");
+ if (bgpMgr.getConfig() != null) {
+ nbrList = bgpMgr.getConfig().getNeighbors();
+ }
+ BgpCounters.parseIpBgpVpnv6AllSummary(neighborStatusMap);
processNeighborStatusMap(neighborStatusMap, nbrList, neighborsRaisedAlarmStatusMap);
}
-
LOG.debug("Finished getting the status of BGP neighbors");
} catch (IOException e) {
LOG.error("Failed to publish bgp counters ", e);
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
+
+import org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private MBeanServer bgpStatsServer = null;
private Map<String, String> countersMap = new HashMap<>();
private String bgpSdncMip = "127.0.0.1";
+ public static final String BGP_VPNV6_FILE = "cmd_ip_bgp_vpnv6_all.txt";
+ public static final String BGP_VPNV4_FILE = "cmd_ip_bgp_vpnv4_all.txt";
+ public static final String BGP_VPNV6_SUMMARY_FILE = "cmd_ip_bgp_vpnv6_all_summary.txt";
+ public static final String BGP_VPNV4_SUMMARY_FILE = "cmd_ip_bgp_vpnv4_all_summary.txt";
public BgpCounters(String mipAddress) {
bgpSdncMip = mipAddress;
resetCounters();
fetchCmdOutputs("cmd_ip_bgp_summary.txt", "show ip bgp summary");
fetchCmdOutputs("cmd_bgp_ipv4_unicast_statistics.txt", "show bgp ipv4 unicast statistics");
- fetchCmdOutputs("cmd_ip_bgp_vpnv4_all.txt", "show ip bgp vpnv4 all");
+ fetchCmdOutputs(BGP_VPNV4_FILE, "show ip bgp vpnv4 all");
+ fetchCmdOutputs(BGP_VPNV6_FILE, "show ip bgp vpnv6 all");
parseIpBgpSummary();
parseIpBgpVpnv4All();
+ parseIpBgpVpnv6All();
if (LOGGER.isDebugEnabled()) {
dumpCounters();
}
case '>':
// Fall through
case '#':
+ sb.append((char) read);
prompt = sb.toString().trim();
break;
default:
cbuf = new char[1024];
while ((read = fromRouter.read(cbuf)) != -1) {
sb.append(cbuf, 0, read);
+ if (sb.toString().trim().endsWith(prompt)) {
+ break;
+ }
}
// Only keep output up to the last prompt
}
}
- private static boolean validate(final String ip) {
+ private static boolean validate(final String ip, af_afi afi) {
if (ip == null || ip.equals("")) {
return false;
}
- Pattern pattern = Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+ String reg = "";
+
+ if (afi == af_afi.AFI_IP) {
+ reg = "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
+ } else {
+ reg = "\\A(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\\z";
+ }
+ Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(ip);
return matcher.matches();
}
-
/*
* The below function parses the output of "show ip bgp summary" saved in a file.
* Below is the snippet for the same :-
return;
}
String strIp = result[0].trim();
- if (!validate(strIp)) {
+ if (!validate(strIp, af_afi.AFI_IP)) {
return;
}
final String as = result[2];
</output>
*/
private void parseIpBgpVpnv4All() {
- File file = new File("cmd_ip_bgp_vpnv4_all.txt");
+ File file = new File(BGP_VPNV4_FILE);
List<String> inputStrs = new ArrayList<>();
try (Scanner scanner = new Scanner(file)) {
countersMap.put(BgpConstants.BGP_COUNTER_TOTAL_PFX,String.valueOf(bgpTotalPfxs));
}
+ /*
+ * The below function parses the output of "show ip bgp vpnv6 all" saved in a file.
+ * Below is the sample output for the same :-
+ * show ip bgp vpnv6 all
+ <output>
+ BGP table version is 0, local router ID is 10.183.181.21
+ ......
+ Route Distinguisher: 100:1
+ *>i2001:db8:0:2::/128 10.183.181.25 0 100 0 ?
+ *>i2001:db8:0:2::/128 10.183.181.25 0 100 0 ?
+ *>i2001:db8:0:2::/128 10.183.181.25 0 100 0 ?
+ *>i2001:db8:0:2::/128 10.183.181.25 0 100 0 ?
+ Route Distinguisher: 100:2
+ *>i2001:db9:0:3::/128 10.183.181.25 0 100 0 ?
+ *>i2001:db9:0:3::/128 10.183.181.25 0 100 0 ?
+ *>i2001:db9:0:3::/128 10.183.181.25 0 100 0 ?
+ </output>
+ */
+ private void parseIpBgpVpnv6All() {
+ File file = new File(BGP_VPNV6_FILE);
+ List<String> inputStrs = new ArrayList<>();
+
+ try (Scanner scanner = new Scanner(file)) {
+ while (scanner.hasNextLine()) {
+ inputStrs.add(scanner.nextLine());
+ }
+ } catch (IOException e) {
+ LOGGER.error("Could not process the file {}", file.getAbsolutePath());
+ return;
+ }
+ for (int i = 0; i < inputStrs.size(); i++) {
+ String instr = inputStrs.get(i);
+ if (instr.contains("Route Distinguisher")) {
+ String[] result = instr.split(":");
+ String rd = result[1].trim() + "_" + result[2].trim();
+ i = processRouteCount(rd, i + 1, inputStrs);
+ }
+ }
+ }
+
private int processRouteCount(String rd, int startIndex, List<String> inputStrs) {
int num = startIndex;
int routeCount = 0;
countersMap.clear();
resetFile("cmd_ip_bgp_summary.txt");
resetFile("cmd_bgp_ipv4_unicast_statistics.txt");
- resetFile("cmd_ip_bgp_vpnv4_all.txt");
+ resetFile(BGP_VPNV4_FILE);
+ resetFile(BGP_VPNV6_FILE);
}
static void resetFile(String fileName) {
}
}
- static Map<String, String> parseIpBgpVpnv4AllSummary(Map<String, String> countMap) {
- File file = new File("cmd_ip_bgp_vpnv4_all_summary.txt");
+ static Map<String, String> parseIpBgpVpnAllSummary(Map<String, String> countMap,
+ String cmdFile,
+ af_afi afi) {
+ File file = new File(cmdFile);
try (Scanner scanner = new Scanner(file)) {
boolean startEntries = false;
String strIp = result[0].trim();
LOGGER.trace("strIp " + strIp);
- if (!validate(strIp)) {
+ if (!validate(strIp, afi)) {
break;
}
String statePfxRcvd = result[9];
return countMap;
}
+
+ static Map<String, String> parseIpBgpVpnv4AllSummary(Map<String, String> countMap) {
+ return BgpCounters.parseIpBgpVpnAllSummary(countMap,
+ BGP_VPNV4_SUMMARY_FILE,
+ af_afi.AFI_IP);
+ }
+
+ static Map<String, String> parseIpBgpVpnv6AllSummary(Map<String, String> countMap) {
+ return BgpCounters.parseIpBgpVpnAllSummary(countMap,
+ BGP_VPNV6_SUMMARY_FILE,
+ af_afi.AFI_IPV6);
+ }
}