use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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;
}
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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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 = new ArrayList<AddressFamiliesVrf>(vrf.nonnullAddressFamiliesVrf().values());
}
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(VrfsContainer.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);
}
// enable multipath by default in all VRFs
setMultipaths(rd, BgpConstants.BGP_DEFAULT_MULTIPATH);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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] " + ebgpMultihops);
printAddNeighborHelp();
return;
}
} catch (NumberFormatException e) {
session.getConsole().println("invalid ebgpMultihops number, valid range [1-255]" + ebgpMultihops);
printAddNeighborHelp();
return;
}
}
if (addressFamily != null) {
if (!addressFamily.equals("lu") && !addressFamily.equals("vpnv4") && !addressFamily.equals("vpnv6") && !addressFamily.equals("evpn")) {
session.getConsole().println("error: Address family must be lu/evpn/vpnv4/vpnv6 ");
return;
}
int afi;
int safi;
if (addressFamily.equals("vpnv6")) {
afi = 2;
safi = 5;
} else if (addressFamily.equals("evpn")) {
afi = 3;
safi = 6;
} else if (addressFamily.equals("lu")) {
afi = 1;
safi = 4;
} else if (addressFamily.equals("vpnv4")) {
afi = 1;
safi = 5;
} else {
session.getConsole().println("invalid addressFamily valid values lu/evpn/vpnv4/vpnv6");
printAddNeighborHelp();
return;
}
}
if (getAsNumber(ip) != -1) {
session.getConsole().println("neighbor with ip " + ip + " already exists");
return;
}
bgpConfigurationManager.addNeighbor(ip, Long.parseLong(asNumber), md5secret);
if (addressFamily != null) {
bgpConfigurationManager.addAddressFamily(ip, af_afi.AFI_IP.getValue(), af_safi.valueOf(addressFamily).getValue());
}
if (ebgpMultihops != null) {
bgpConfigurationManager.addEbgpMultihop(ip, Integer.parseInt(ebgpMultihops));
}
if (sourceIp != null) {
bgpConfigurationManager.addUpdateSource(ip, sourceIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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) {
Map<VrfEntryKey, VrfEntry> keyVrfEntryMap = vrfTable.getVrfEntry();
if (keyVrfEntryMap == null) {
LOG.error("removeVrfSubFamilyFromDS : VrfEntry not found for rd {}", rd);
return;
}
for (VrfEntry vrfEntry : keyVrfEntryMap.values()) {
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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily in project bgpcep by opendaylight.
the class Stateful07LSPIdentifierIpv4TlvParser method parseTlv.
@Override
public LspIdentifiers parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
return null;
}
Preconditions.checkArgument(buffer.readableBytes() == V4_LENGTH, "Length %s does not match LSP Identifiers Ipv4 tlv length.", buffer.readableBytes());
final Ipv4Builder builder = new Ipv4Builder();
builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer));
final LspId lspId = new LspId((long) buffer.readUnsignedShort());
final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf(buffer)));
builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(buffer));
final AddressFamily afi = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
}
Aggregations