Search in sources :

Example 66 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class BgpConfigurationManager method delVrf.

public boolean delVrf(String rd, AddressFamily addressFamily) {
    if (addressFamily == null) {
        LOG.error("delVrf: vrf {}, addressFamily invalid", rd);
        return false;
    }
    delMultipaths(rd);
    AddressFamiliesVrfBuilder adfBuilder = new AddressFamiliesVrfBuilder();
    if (addressFamily.equals(AddressFamily.IPV4)) {
        adfBuilder.setAfi((long) af_afi.AFI_IP.getValue());
        adfBuilder.setSafi((long) af_safi.SAFI_MPLS_VPN.getValue());
    } else if (addressFamily.equals(AddressFamily.IPV6)) {
        adfBuilder.setAfi((long) af_afi.AFI_IPV6.getValue());
        adfBuilder.setSafi((long) af_safi.SAFI_MPLS_VPN.getValue());
    } else if (addressFamily.equals(AddressFamily.L2VPN)) {
        adfBuilder.setAfi((long) af_afi.AFI_IP.getValue());
        adfBuilder.setSafi((long) af_safi.SAFI_EVPN.getValue());
    }
    LOG.debug("delVrf: Received Delete VRF : rd:{}, address family: {} {}", rd, adfBuilder.getAfi(), adfBuilder.getSafi());
    Vrfs vrfOriginal = bgpUtil.getVrfFromRd(rd);
    if (vrfOriginal == null) {
        LOG.error("delVrf: no vrf with existing rd {}. step aborted", rd);
        return false;
    }
    InstanceIdentifier.InstanceIdentifierBuilder<Vrfs> iib = InstanceIdentifier.builder(Bgp.class).child(VrfsContainer.class).child(Vrfs.class, new VrfsKey(rd));
    InstanceIdentifier<Vrfs> iid = iib.build();
    @SuppressWarnings("static-access") InstanceIdentifier<Bgp> iid6 = iid.builder(Bgp.class).build().child(MultipathContainer.class).child(Multipath.class, new MultipathKey(adfBuilder.getAfi(), adfBuilder.getSafi())).create(Bgp.class);
    InstanceIdentifierBuilder<Vrfs> iib3 = iid6.child(VrfsContainer.class).child(Vrfs.class, new VrfsKey(rd)).builder();
    InstanceIdentifier<Vrfs> iidFinal = iib3.build();
    // ** update or delete the vrfs with the rest of AddressFamilies already present in the last list
    AddressFamiliesVrf adfToDel = adfBuilder.build();
    List<AddressFamiliesVrf> adfListOriginal = new ArrayList<>(vrfOriginal.nonnullAddressFamiliesVrf().values());
    List<AddressFamiliesVrf> adfListToRemoveFromOriginal = new ArrayList<>();
    adfListOriginal.forEach(adf -> {
        if (adf.equals(adfToDel)) {
            adfListToRemoveFromOriginal.add(adfToDel);
            return;
        }
    });
    for (AddressFamiliesVrf adfToRemove : adfListToRemoveFromOriginal) {
        adfListOriginal.remove(adfToRemove);
        try {
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, iid, vrfOriginal);
        } catch (TransactionCommitFailedException e) {
            LOG.error("delVrf: Error updating VRF to datastore", e);
            throw new RuntimeException(e);
        }
    }
    if (adfListOriginal.isEmpty()) {
        LOG.debug("delVrf: delete iid: {}", iidFinal);
        delete(iidFinal);
        return true;
    }
    // not all is removed
    return false;
}
Also used : Vrfs(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.Vrfs) MultipathKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.MultipathKey) VrfsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.VrfsKey) VrfsContainer(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfsContainer) ArrayList(java.util.ArrayList) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp) Multipath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.multipathcontainer.Multipath) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) AddressFamiliesVrf(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.vrfs.AddressFamiliesVrf) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) AddressFamiliesVrfBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfscontainer.vrfs.AddressFamiliesVrfBuilder)

Example 67 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class BgpConfigurationManager method addAddressFamily.

public void addAddressFamily(String nbrIp, int afi, int safi) {
    Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
    InstanceIdentifier.InstanceIdentifierBuilder<AddressFamilies> iib = InstanceIdentifier.builder(Bgp.class).child(NeighborsContainer.class).child(Neighbors.class, new NeighborsKey(nbrAddr)).child(AddressFamilies.class, new AddressFamiliesKey((long) afi, (long) safi));
    InstanceIdentifier<AddressFamilies> iid = iib.build();
    AddressFamilies dto = new AddressFamiliesBuilder().setPeerIp(nbrAddr).setAfi((long) afi).setSafi((long) safi).build();
    update(iid, dto);
}
Also used : AddressFamilies(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamilies) 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) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) AddressFamiliesBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighborscontainer.neighbors.AddressFamiliesBuilder) 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 68 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class BgpConfigurationManager method startConfig.

public void startConfig(String bgpHost, int thriftPort) {
    InstanceIdentifier.InstanceIdentifierBuilder<ConfigServer> iib = InstanceIdentifier.builder(Bgp.class).child(ConfigServer.class);
    InstanceIdentifier<ConfigServer> iid = iib.build();
    Ipv4Address ipAddr = new Ipv4Address(bgpHost);
    ConfigServer dto = new ConfigServerBuilder().setHost(ipAddr).setPort((long) thriftPort).build();
    update(iid, dto);
}
Also used : ConfigServerBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.ConfigServerBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp) ConfigServer(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.ConfigServer) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 69 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class BgpConfigurationManager method startBgp.

public void startBgp(long as, String routerId, int spt, boolean fbit) {
    IpAddress rid = routerId == null ? null : IpAddressBuilder.getDefaultInstance(routerId);
    Long staleTime = (long) spt;
    InstanceIdentifier.InstanceIdentifierBuilder<AsId> iib = InstanceIdentifier.builder(Bgp.class).child(AsId.class);
    InstanceIdentifier<AsId> iid = iib.build();
    AsId dto = new AsIdBuilder().setLocalAs(as).setRouterId(rid).setStalepathTime(staleTime).setAnnounceFbit(fbit).build();
    update(iid, dto);
}
Also used : AsId(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsId) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp) AsIdBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.AsIdBuilder)

Example 70 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project netvirt by opendaylight.

the class BgpConfigurationManager method onUpdatePushRoute.

/* onUpdatePushRoute
     * Get Stale fibDSWriter map, and compare current route/fibDSWriter entry.
     *  - Entry compare shall include NextHop, Label.
     *  - If entry matches: delete from STALE Map. NO Change to FIB Config DS.
     *  - If entry not found, add to FIB Config DS.
     *  - If entry found, but either Label/NextHop doesn't match.
     *      - Update FIB Config DS with modified values.
     *      - delete from Stale Map.
     */
public void onUpdatePushRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop, String macaddress, Uint32 label, Uint32 l2label, String routermac, af_afi afi) {
    PrefixUpdateEvent prefixUpdateEvent = new PrefixUpdateEvent(protocolType, rd, prefix, plen, nextHop, macaddress, label, l2label, routermac, afi);
    bgpUpdatesHistory.addToHistory(TransactionType.ADD, prefixUpdateEvent);
    boolean addroute = false;
    boolean macupdate = false;
    Uint32 l3vni = Uint32.ZERO;
    VrfEntry.EncapType encapType = VrfEntry.EncapType.Mplsgre;
    if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
        encapType = VrfEntry.EncapType.Vxlan;
        VpnInstanceOpDataEntry vpnInstanceOpDataEntry = bgpUtil.getVpnInstanceOpData(rd);
        if (vpnInstanceOpDataEntry != null) {
            if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
                LOG.info("Got RT2 route for RD {} l3label {} l2label {} from tep {} with mac {} remote RD {}", vpnInstanceOpDataEntry.getVpnInstanceName(), label, l2label, nextHop, macaddress, rd);
                addTepToElanDS(rd, nextHop, macaddress, l2label);
                macupdate = true;
            } else {
                l3vni = vpnInstanceOpDataEntry.getL3vni();
            }
        } else {
            LOG.error("No corresponding vpn instance found for rd {}. Aborting.", rd);
            return;
        }
    }
    if (!staledFibEntriesMap.isEmpty()) {
        // restart Scenario, as MAP is not empty.
        Map<String, Uint32> map = staledFibEntriesMap.get(rd);
        if (map != null) {
            String prefixNextHop = appendNextHopToPrefix(prefix + "/" + plen, nextHop);
            Uint32 labelInStaleMap = map.get(prefixNextHop);
            if (null == labelInStaleMap) {
                // New Entry, which happened to be added during restart.
                addroute = true;
            } else {
                map.remove(prefixNextHop);
                if (isRouteModified(label, labelInStaleMap)) {
                    LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
                    // Existing entry, where in Label got modified during restart
                    addroute = true;
                }
            }
        } else {
            LOG.debug("rd {} map is null while processing prefix {} ", rd, prefix);
            addroute = true;
        }
    } else {
        LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
        addroute = true;
    }
    if (macupdate) {
        LOG.info("ADD: Adding Mac Fib entry rd {} mac{} nexthop {} l2vni {}", rd, macaddress, nextHop, l2label);
        fibDSWriter.addMacEntryToDS(rd, macaddress, prefix, Collections.singletonList(nextHop), encapType, l2label, routermac, RouteOrigin.BGP);
        LOG.info("ADD: Added Mac Fib entry rd {} prefix {} nexthop {} label {}", rd, macaddress, nextHop, l2label);
    } else if (addroute) {
        LOG.info("ADD: Adding Fib entry rd {} prefix {} nexthop {} label {} afi {}", rd, prefix, nextHop, label, afi);
        // TODO: modify addFibEntryToDS signature
        List<String> nextHopList = Collections.singletonList(nextHop);
        fibDSWriter.addFibEntryToDS(rd, prefix + "/" + plen, nextHopList, encapType, label, l3vni, routermac, RouteOrigin.BGP);
        LOG.info("ADD: Added Fib entry rd {} prefix {} nexthop {} label {}", rd, prefix, nextHop, label);
        String vpnName = bgpUtil.getVpnNameFromRd(rd);
        if (vpnName != null) {
            vpnLinkService.leakRouteIfNeeded(vpnName, prefix, nextHopList, label, RouteOrigin.BGP, NwConstants.ADD_FLOW);
        }
    }
}
Also used : MacVrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntry) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) ArrayList(java.util.ArrayList) List(java.util.List) DcgwTepList(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.DcgwTepList) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Aggregations

ArrayList (java.util.ArrayList)120 Test (org.junit.Test)85 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)71 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)64 ExecutionException (java.util.concurrent.ExecutionException)56 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)47 List (java.util.List)46 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)38 Logger (org.slf4j.Logger)38 LoggerFactory (org.slf4j.LoggerFactory)38 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)37 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)35 Collections (java.util.Collections)35 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)35 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)34 Map (java.util.Map)33 Inject (javax.inject.Inject)32 Singleton (javax.inject.Singleton)32 BigInteger (java.math.BigInteger)31 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)29