Search in sources :

Example 11 with Neighbors

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors in project netvirt by opendaylight.

the class ConfigureBgpCli method getAsNumber.

public long getAsNumber(String nbrIp) {
    Bgp conf = bgpManager.getConfig();
    if (conf == null) {
        return -1;
    }
    List<Neighbors> nbrs = conf.getNeighbors();
    if (nbrs == null) {
        return -1;
    }
    for (Neighbors nbr : nbrs) {
        if (nbrIp.equals(nbr.getAddress().getValue())) {
            return nbr.getRemoteAs();
        }
    }
    return -1;
}
Also used : Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)

Example 12 with Neighbors

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors 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;
}
Also used : Vrfs(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Vrfs) Networks(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Networks) FileNotFoundException(java.io.FileNotFoundException) EbgpMultihop(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.EbgpMultihop) AsId(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsId) AddressFamilies(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.AddressFamilies) UpdateSource(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.UpdateSource) Logging(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Logging) PrintStream(java.io.PrintStream) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp) VrfMaxpath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfMaxpath) Multipath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Multipath) GracefulRestart(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart) AddressFamiliesVrf(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfs.AddressFamiliesVrf) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 13 with Neighbors

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors in project netvirt by opendaylight.

the class Router method doExecute.

@Override
protected Object doExecute() {
    switch(action) {
        case "add":
            // check: rtr already running?
            long asn = 0;
            int stalePath = 0;
            boolean fb = false;
            if (asNum == null) {
                session.getConsole().println("error: " + AS + " is needed");
                return null;
            }
            if (!Commands.isValid(session.getConsole(), asNum, Commands.Validators.INT, AS)) {
                return null;
            }
            asn = Long.parseLong(asNum);
            if (rid != null && !Commands.isValid(session.getConsole(), rid, Commands.Validators.IPADDR, RID)) {
                return null;
            }
            if (spt != null) {
                if (!Commands.isValid(session.getConsole(), spt, Commands.Validators.INT, SP)) {
                    return null;
                } else {
                    stalePath = Integer.parseInt(spt);
                }
            }
            if (fbit != null) {
                switch(fbit) {
                    case "on":
                        fb = true;
                        break;
                    case "off":
                        fb = false;
                        break;
                    default:
                        session.getConsole().println("error: " + FB + " must be on or off");
                        return null;
                }
            }
            bgpManager.startBgp(asn, rid, stalePath, fb);
            break;
        case "del":
            // check: nothing to stop?
            if (asNum != null || rid != null || spt != null || fbit != null) {
                session.getConsole().println("note: option(s) not needed; ignored");
            }
            Bgp conf = bgpManager.getConfig();
            if (conf == null) {
                session.getConsole().println("error : no BGP configs present");
                break;
            }
            List<Neighbors> nbrs = conf.getNeighbors();
            if (nbrs != null && nbrs.size() > 0) {
                session.getConsole().println("error: all BGP congiguration must be deleted " + "before stopping the router instance");
                break;
            }
            bgpManager.stopBgp();
            break;
        default:
            return usage();
    }
    return null;
}
Also used : Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)

Example 14 with Neighbors

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors in project netvirt by opendaylight.

the class BgpAlarms method processNeighborStatusMap.

private void processNeighborStatusMap(Map<String, String> nbrStatusMap, List<Neighbors> nbrs) {
    if (nbrs == null || nbrs.isEmpty()) {
        LOG.trace("No BGP neighbors configured.");
        return;
    }
    for (Neighbors nbr : nbrs) {
        boolean alarmToRaise = true;
        if (nbrStatusMap != null && nbrStatusMap.containsKey(nbr.getAddress().getValue())) {
            String nbrshipStatus = nbrStatusMap.get(nbr.getAddress().getValue());
            LOG.trace("nbr {} status {}", nbr.getAddress().getValue(), nbrshipStatus);
            try {
                Integer.parseInt(nbrshipStatus);
                alarmToRaise = false;
            } catch (NumberFormatException e) {
                LOG.trace("Exception thrown in parsing the integers. {}", e);
            }
            final BgpAlarmStatus alarmStatus = neighborsRaisedAlarmStatusMap.get(nbr.getAddress().getValue());
            if (alarmToRaise) {
                if (alarmStatus == null || alarmStatus != BgpAlarmStatus.RAISED) {
                    LOG.trace("alarm raised for {}.", nbr.getAddress().getValue());
                    raiseBgpNbrDownAlarm(nbr.getAddress().getValue());
                } else {
                    LOG.trace("alarm raised already for {}", nbr.getAddress().getValue());
                }
            } else {
                if (alarmStatus == null || alarmStatus != BgpAlarmStatus.CLEARED) {
                    clearBgpNbrDownAlarm(nbr.getAddress().getValue());
                    LOG.trace("alarm cleared for {}", nbr.getAddress().getValue());
                } else {
                    LOG.trace("alarm cleared already for {}", nbr.getAddress().getValue());
                }
            }
        }
    }
}
Also used : Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)

Aggregations

Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)11 Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)7 TException (org.apache.thrift.TException)2 BgpRouterException (org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouterException)2 org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi (org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi)2 org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi (org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi)2 Global (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global)2 Neighbors (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors)2 AsId (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsId)2 GracefulRestart (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart)2 Logging (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Logging)2 Multipath (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Multipath)2 NeighborsKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NeighborsKey)2 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Networks)2 VrfMaxpath (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfMaxpath)2 Vrfs (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Vrfs)2 AddressFamilies (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.AddressFamilies)2 EbgpMultihop (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.EbgpMultihop)2 UpdateSource (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.UpdateSource)2 AddressFamiliesVrf (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfs.AddressFamiliesVrf)2