Search in sources :

Example 1 with MultipathKey

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.MultipathKey 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;
    }
    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());
    }
    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(Vrfs.class, new VrfsKey(rd));
    InstanceIdentifier<Vrfs> iid = iib.build();
    @SuppressWarnings("static-access") InstanceIdentifier<Bgp> iid6 = iid.builder(Bgp.class).build().child(Multipath.class, new MultipathKey(adfBuilder.getAfi(), adfBuilder.getSafi())).create(Bgp.class);
    InstanceIdentifierBuilder<Vrfs> iib3 = iid6.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 = vrfOriginal.getAddressFamiliesVrf() == null ? new ArrayList<>() : vrfOriginal.getAddressFamiliesVrf();
    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()) {
        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.Vrfs) MultipathKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.MultipathKey) VrfsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfsKey) 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.Multipath) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) AddressFamiliesVrf(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfs.AddressFamiliesVrf) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) AddressFamiliesVrfBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfs.AddressFamiliesVrfBuilder)

Example 2 with MultipathKey

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

the class BgpConfigurationManager method setMultipathStatus.

public void setMultipathStatus(af_afi afi, af_safi safi, boolean enable) {
    long lafi = afi.getValue();
    long lsafi = safi.getValue();
    InstanceIdentifier.InstanceIdentifierBuilder<Multipath> iib = InstanceIdentifier.builder(Bgp.class).child(Multipath.class, new MultipathKey(Long.valueOf(afi.getValue()), Long.valueOf(safi.getValue())));
    Multipath dto = new MultipathBuilder().setAfi(lafi).setSafi(lsafi).setMultipathEnabled(enable).build();
    update(iib.build(), dto);
}
Also used : Multipath(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Multipath) MultipathKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.MultipathKey) MultipathBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.MultipathBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Bgp(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)

Aggregations

Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)2 Multipath (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Multipath)2 MultipathKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.MultipathKey)2 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)2 ArrayList (java.util.ArrayList)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 MultipathBuilder (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.MultipathBuilder)1 Vrfs (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Vrfs)1 VrfsKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfsKey)1 AddressFamiliesVrf (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfs.AddressFamiliesVrf)1 AddressFamiliesVrfBuilder (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.vrfs.AddressFamiliesVrfBuilder)1