Search in sources :

Example 1 with EbgpMultihop

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop in project netvirt by opendaylight.

the class BgpConfigurationManager method delEbgpMultihop.

public void delEbgpMultihop(String nbrIp) {
    Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
    InstanceIdentifier.InstanceIdentifierBuilder<EbgpMultihop> iib = InstanceIdentifier.builder(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class, new NeighborsKey(nbrAddr)).child(EbgpMultihop.class);
    InstanceIdentifier<EbgpMultihop> iid = iib.build();
    delete(iid);
}
Also used : EbgpMultihop(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp) NeighborsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsKey) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 2 with EbgpMultihop

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop in project netvirt by opendaylight.

the class BgpConfigurationManager method addEbgpMultihop.

public void addEbgpMultihop(String nbrIp, int hops) {
    Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
    InstanceIdentifier.InstanceIdentifierBuilder<EbgpMultihop> iib = InstanceIdentifier.builder(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class, new NeighborsKey(nbrAddr)).child(EbgpMultihop.class);
    InstanceIdentifier<EbgpMultihop> iid = iib.build();
    EbgpMultihop dto = new EbgpMultihopBuilder().setPeerIp(nbrAddr).setNhops((long) hops).build();
    update(iid, dto);
}
Also used : EbgpMultihop(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp) EbgpMultihopBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihopBuilder) NeighborsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsKey) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 3 with EbgpMultihop

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop 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);
                replayDone = true;
            } catch (TApplicationException tae) {
                LOG.debug("Replaying addNbr {}, tapplicationexception: ", replayNbr.getNbr().getAddress().getValue(), tae);
                if (tae.getType() == BgpRouterException.BGP_ERR_PEER_EXISTS) {
                    LOG.debug("Replaying addNbr Neighbor already present");
                    replayDone = true;
                } else {
                    LOG.error("Replaying addNbr {}, exception: ", replayNbr.getNbr().getAddress().getValue(), tae);
                }
            } catch (TException | BgpRouterException eNbr) {
                LOG.debug("Replaying addNbr {}, exception: ", replayNbr.getNbr().getAddress().getValue(), eNbr);
            }
            LOG.debug("Replay addNbr {} successful", replayNbr.getNbr().getAddress().getValue());
            // Update Source handling
            UpdateSource us = replayNbr.getNbr().getUpdateSource();
            if (us != null) {
                LOG.debug("Replaying updatesource {} to peer {}", us.getSourceIp().getValue(), us.getPeerIp().getValue());
                try {
                    br.addUpdateSource(us.getPeerIp().getValue(), us.getSourceIp().getValue());
                } catch (TException | BgpRouterException eUs) {
                    LOG.debug("Replaying UpdateSource for Nbr {}, exception:", replayNbr.getNbr().getAddress().getValue(), eUs);
                }
                LOG.debug("Replay updatesource {} successful", us.getSourceIp().getValue());
            }
            // Ebgp Multihope
            EbgpMultihop en = replayNbr.getNbr().getEbgpMultihop();
            if (en != null) {
                try {
                    br.addEbgpMultihop(en.getPeerIp().getValue(), en.getNhops().intValue());
                } catch (TException | BgpRouterException eEbgpMhop) {
                    LOG.debug("Replaying EbgpMultihop for Nbr {}, exception: ", replayNbr.getNbr().getAddress().getValue(), eEbgpMhop);
                }
            }
            // keyAddressFamiliesMap
            Map<AddressFamiliesKey, AddressFamilies> keyAddressFamiliesMap = replayNbr.getNbr().getAddressFamilies();
            if (keyAddressFamiliesMap != null) {
                for (AddressFamilies af : keyAddressFamiliesMap.values()) {
                    af_afi afi = af_afi.findByValue(af.getAfi().intValue());
                    af_safi safi = af_safi.findByValue(af.getSafi().intValue());
                    try {
                        br.addAddressFamily(af.getPeerIp().getValue(), afi, safi);
                    } catch (TException | BgpRouterException eAFs) {
                        LOG.debug("Replaying AddressFamily for Nbr {}, exception:", replayNbr.getNbr().getAddress().getValue(), eAFs);
                    }
                }
            }
            // replay is success --> no need to replay this nbr in next iteration.
            replayNbr.setShouldRetry(replayDone ? false : true);
        }
    } while (nbrRetry.decrementAndRetry());
    boolean replaySuccess = true;
    for (ReplayNbr replayNbr : replayNbrList) {
        replaySuccess = replaySuccess && !replayNbr.isShouldRetry();
        if (replaySuccess == false) {
            LOG.error("replayNbrConfig: will be cancelling stale cleanup, cfg nbr: {} Failed:", replayNbr.getNbr().getAddress().getValue());
        }
    }
    return replaySuccess;
}
Also used : TException(org.apache.thrift.TException) AddressFamiliesKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamiliesKey) ArrayList(java.util.ArrayList) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors) EbgpMultihop(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop) TApplicationException(org.apache.thrift.TApplicationException) org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi(org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi) BgpRouterException(org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouterException) AddressFamilies(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamilies) org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi(org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi) UpdateSource(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.UpdateSource)

Example 4 with EbgpMultihop

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop in project netvirt by opendaylight.

the class Cache method doExecute.

@SuppressWarnings({ "resource", "checkstyle:RegexpSinglelineJava" })
@Override
protected Object doExecute() {
    boolean listVrfs = false;
    boolean listNets = false;
    PrintStream ps = System.out;
    if (action != null) {
        return usage();
    }
    PrintStream fileStream = null;
    try {
        if (ofile != null) {
            try {
                fileStream = new PrintStream(ofile);
                ps = fileStream;
            } catch (FileNotFoundException e) {
                System.out.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:
                        System.out.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) {
            Long asNum = asId.getLocalAs().longValue();
            IpAddress routerId = asId.getRouterId();
            Long spt = asId.getStalepathTime().toJava();
            Boolean afb = asId.isAnnounceFbit();
            String rid = routerId == null ? "<n/a>" : routerId.stringValue();
            // 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().toJava();
            }
            ps.printf("%nBGP Router%n");
            ps.printf("\t%-15s  %s%n\t%-15s  %s%n\t%-15s  %s%n\t%-15s  %s%n", ASSTR, asNum.toString(), 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());
        }
        Map<NeighborsKey, Neighbors> keyNeighborsMap = (config.getNeighborsContainer() == null) ? null : config.getNeighborsContainer().getNeighbors();
        if (keyNeighborsMap != null) {
            ps.printf("%nNeighbors%n");
            for (Neighbors nbr : keyNeighborsMap.values()) {
                ps.printf("\t%s%n\t\t%-16s  %d%n", nbr.getAddress().getValue(), ASSTR, nbr.getRemoteAs());
                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);
                Map<AddressFamiliesKey, AddressFamilies> keyAddressFamiliesMap = nbr.getAddressFamilies();
                if (keyAddressFamiliesMap != null) {
                    for (AddressFamilies af : keyAddressFamiliesMap.values()) {
                        // 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) {
            Map<VrfsKey, Vrfs> keyVrfsMap = (config.getVrfsContainer() == null) ? null : config.getVrfsContainer().getVrfs();
            if (keyVrfsMap != null) {
                ps.printf("%nVRFs%n");
                for (Vrfs vrf : keyVrfsMap.values()) {
                    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().values()) {
                        ps.printf("%n\t\tafi %d safi %d", adf.getAfi(), adf.getSafi());
                    }
                    ps.printf("%n");
                }
            }
        }
        if (listNets) {
            Map<NetworksKey, Networks> keyNetworksMap = (config.getNetworksContainer() == null) ? null : config.getNetworksContainer().getNetworks();
            if (keyNetworksMap != null) {
                ps.printf("%nNetworks%n");
                for (Networks net : keyNetworksMap.values()) {
                    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);
                }
            }
        }
        Map<MultipathKey, Multipath> keyMultipathMap = config.getMultipathContainer() == null ? null : config.getMultipathContainer().getMultipath();
        Map<VrfMaxpathKey, VrfMaxpath> keyVrfMaxpathMap = config.getVrfMaxpathContainer() == null ? null : config.getVrfMaxpathContainer().getVrfMaxpath();
        if (keyMultipathMap != null) {
            ps.printf("%nMultipath%n");
            for (Multipath multipath : keyMultipathMap.values()) {
                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 (keyVrfMaxpathMap != null) {
                        ps.printf("\t%-16s  %s%n", RDSTR, MPSTR);
                        for (VrfMaxpath vrfMaxpath : keyVrfMaxpathMap.values()) {
                            String rd = vrfMaxpath.getRd();
                            int maxpath = vrfMaxpath.getMaxpaths().toJava();
                            ps.printf("\t%-16s  %d%n", rd, maxpath);
                        }
                    }
                }
            }
        }
    } finally {
        if (fileStream != null) {
            fileStream.close();
        }
    }
    return null;
}
Also used : Vrfs(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.Vrfs) Networks(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks) VrfsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.VrfsKey) FileNotFoundException(java.io.FileNotFoundException) EbgpMultihop(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.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.neighborscontainer.neighbors.AddressFamilies) UpdateSource(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.UpdateSource) Logging(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Logging) PrintStream(java.io.PrintStream) MultipathKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.MultipathKey) VrfMaxpathKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfmaxpathcontainer.VrfMaxpathKey) AddressFamiliesKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamiliesKey) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.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.vrfmaxpathcontainer.VrfMaxpath) Multipath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.Multipath) NetworksKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey) 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.vrfscontainer.vrfs.AddressFamiliesVrf) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) NeighborsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsKey)

Aggregations

Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.Neighbors)4 EbgpMultihop (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.EbgpMultihop)4 Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)3 NeighborsKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.NeighborsKey)3 AddressFamilies (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamilies)2 AddressFamiliesKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamiliesKey)2 UpdateSource (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.UpdateSource)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)2 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 TApplicationException (org.apache.thrift.TApplicationException)1 TException (org.apache.thrift.TException)1 BgpRouterException (org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouterException)1 org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi (org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi)1 org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi (org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi)1 AsId (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsId)1 GracefulRestart (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart)1 Logging (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Logging)1