Search in sources :

Example 1 with AddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.AddressFamily in project netvirt by opendaylight.

the class BgpConfigurationManager method addVrf.

// TODO: add LayerType as arg - supports command
public void addVrf(String rd, List<String> irts, List<String> erts, AddressFamily addressFamily) {
    Vrfs vrf = bgpUtil.getVrfFromRd(rd);
    List<AddressFamiliesVrf> adfList = new ArrayList<>(1);
    if (vrf != null) {
        adfList = vrf.getAddressFamiliesVrf();
    }
    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());
    }
    AddressFamiliesVrf adf = adfBuilder.build();
    adfList.add(adf);
    InstanceIdentifier.InstanceIdentifierBuilder<Vrfs> iib = InstanceIdentifier.builder(Bgp.class).child(Vrfs.class, new VrfsKey(rd));
    InstanceIdentifier<Vrfs> iid = iib.build();
    Vrfs dto = new VrfsBuilder().setRd(rd).setImportRts(irts).setExportRts(erts).setAddressFamiliesVrf(adfList).build();
    List<AddressFamiliesVrf> listAdFamilies = mapNewAdFamily.get(rd);
    if (listAdFamilies != null) {
        listAdFamilies.add(adf);
    } else {
        mapNewAdFamily.put(rd, adfList);
    }
    try {
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, iid, dto);
    } catch (TransactionCommitFailedException e) {
        LOG.error("Error adding VRF to datastore", e);
        throw new RuntimeException(e);
    }
}
Also used : Vrfs(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Vrfs) VrfsBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfsBuilder) 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) 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 AddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.AddressFamily 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 3 with AddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.AddressFamily in project netvirt by opendaylight.

the class ConfigureBgpCli method addNeighbor.

protected void addNeighbor() {
    if (!validateAsNumber(asNumber)) {
        printAddNeighborHelp();
        return;
    }
    boolean validIp = validateIp(ip);
    if (!validIp) {
        session.getConsole().println("invalid neighbor ip");
        printAddNeighborHelp();
        return;
    }
    TcpMd5SignaturePasswordType md5secret = null;
    if (md5passwordOption != null) {
        try {
            md5secret = new TcpMd5SignaturePasswordType(md5passwordOption);
        } catch (IllegalArgumentException e) {
            session.getConsole().println(new StringBuilder("invalid MD5 password: ").append(e.getMessage()).toString());
            printAddNeighborHelp();
            return;
        }
    }
    if (sourceIp != null) {
        validIp = validateIp(sourceIp);
        if (!validIp) {
            session.getConsole().println("invalid source ip");
            printAddNeighborHelp();
            return;
        }
    }
    if (ebgpMultihops != null) {
        try {
            long val = Long.parseLong(ebgpMultihops);
            if (val < 1 || val > 255) {
                session.getConsole().println("invalid ebgpMultihops number , valid range [1,255] ");
                printAddNeighborHelp();
                return;
            }
        } catch (NumberFormatException e) {
            session.getConsole().println("invalid ebgpMultihops number, valid range [1-255]");
            printAddNeighborHelp();
            return;
        }
    }
    if (addressFamily != null) {
        try {
            af_safi.valueOf(addressFamily);
        } catch (IllegalArgumentException e) {
            session.getConsole().println("invalid addressFamily valid values SAFI_IPV4_LABELED_UNICAST | SAFI_MPLS_VPN");
            printAddNeighborHelp();
            return;
        }
    }
    if (getAsNumber(ip) != -1) {
        session.getConsole().println("neighbor with ip " + ip + " already exists");
        return;
    }
    bgpManager.addNeighbor(ip, Long.parseLong(asNumber), md5secret);
    if (addressFamily != null) {
        bgpManager.addAddressFamily(ip, af_afi.AFI_IP, af_safi.valueOf(addressFamily));
    }
    if (ebgpMultihops != null) {
        bgpManager.addEbgpMultihop(ip, Integer.parseInt(ebgpMultihops));
    }
    if (sourceIp != null) {
        bgpManager.addUpdateSource(ip, sourceIp);
    }
}
Also used : TcpMd5SignaturePasswordType(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.TcpMd5SignaturePasswordType)

Example 4 with AddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.AddressFamily in project netvirt by opendaylight.

the class FibDSWriter method removeVrfSubFamilyFromDS.

public synchronized void removeVrfSubFamilyFromDS(String rd, AddressFamily addressFamily) {
    if (rd == null) {
        return;
    }
    LOG.debug("removeVrfSubFamilyFromDS : addressFamily {} from vrf rd {}", addressFamily, rd);
    InstanceIdentifier<VrfTables> id = InstanceIdentifier.create(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
    try {
        VrfTables vrfTable = singleTxDB.syncRead(LogicalDatastoreType.CONFIGURATION, id);
        if (vrfTable != null) {
            List<VrfEntry> vrfEntries = vrfTable.getVrfEntry();
            if (vrfEntries == null) {
                LOG.error("removeVrfSubFamilyFromDS : VrfEntry not found for rd {}", rd);
                return;
            }
            for (VrfEntry vrfEntry : vrfEntries) {
                boolean found = false;
                if (vrfEntry.getEncapType() != null) {
                    if (!vrfEntry.getEncapType().equals(EncapType.Mplsgre) && addressFamily == AddressFamily.L2VPN) {
                        found = true;
                    } else if (vrfEntry.getEncapType().equals(EncapType.Mplsgre)) {
                        if (addressFamily == AddressFamily.IPV4 && FibHelper.isIpv4Prefix(vrfEntry.getDestPrefix())) {
                            found = true;
                        } else if (addressFamily == AddressFamily.IPV6 && FibHelper.isIpv6Prefix(vrfEntry.getDestPrefix())) {
                            found = true;
                        }
                    }
                }
                if (found == false) {
                    continue;
                }
                bgpUtil.removeVrfEntry(rd, vrfEntry);
            }
        }
    } catch (ReadFailedException rfe) {
        LOG.error("removeVrfSubFamilyFromDS : Internal Error rd {}", rd, rfe);
    }
    return;
}
Also used : VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) 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) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)

Example 5 with AddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.AddressFamily in project bgpcep by opendaylight.

the class LUNlriParser method parseNlri.

private static List<CLabeledUnicastDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi, final boolean mPathSupported) {
    if (!nlri.isReadable()) {
        return null;
    }
    final List<CLabeledUnicastDestination> dests = new ArrayList<>();
    while (nlri.isReadable()) {
        final CLabeledUnicastDestinationBuilder builder = new CLabeledUnicastDestinationBuilder();
        if (mPathSupported) {
            builder.setPathId(PathIdUtil.readPathId(nlri));
        }
        final short length = nlri.readUnsignedByte();
        final List<LabelStack> labels = parseLabel(nlri);
        builder.setLabelStack(labels);
        final int labelNum = labels != null ? labels.size() : 1;
        final int prefixLen = length - (LABEL_LENGTH * Byte.SIZE * labelNum);
        builder.setPrefix(parseIpPrefix(nlri, prefixLen, afi));
        dests.add(builder.build());
    }
    return dests;
}
Also used : CLabeledUnicastDestination(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.destination.CLabeledUnicastDestination) LabelStack(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.LabelStack) ArrayList(java.util.ArrayList) CLabeledUnicastDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.destination.CLabeledUnicastDestinationBuilder) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)10 ArrayList (java.util.ArrayList)9 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)6 AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.lsp.identifiers.AddressFamily)6 LspId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId)6 TunnelId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId)6 Test (org.junit.Test)5 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)4 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType)4 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)3 LspIdentifiers (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.LspIdentifiers)3 LspIdentifiersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.identifiers.tlv.LspIdentifiersBuilder)3 Preconditions (com.google.common.base.Preconditions)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 NextHopParserSerializer (org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)2 NlriParser (org.opendaylight.protocol.bgp.parser.spi.NlriParser)2 Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)2 Vrfs (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Vrfs)2 VrfsKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.VrfsKey)2