use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies 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.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies in project bgpcep by opendaylight.
the class AddPathCapabilityHandler method serializeCapability.
@Override
public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
final CParameters1 aug = capability.augmentation(CParameters1.class);
if (aug == null) {
return;
}
final AddPathCapability addPathCap = aug.getAddPathCapability();
if (addPathCap == null) {
return;
}
final List<AddressFamilies> families = addPathCap.getAddressFamilies();
if (families != null) {
final ByteBuf capBuffer = Unpooled.buffer(families.size() * TRIPLET_BYTE_SIZE);
for (final AddressFamilies addressFamily : families) {
final Class<? extends AddressFamily> afi = addressFamily.getAfi();
final Integer afival = this.afiReg.numberForClass(afi);
checkArgument(afival != null, "Unhandled address family " + afi);
final Class<? extends SubsequentAddressFamily> safi = addressFamily.getSafi();
final Integer safival = this.safiReg.numberForClass(safi);
checkArgument(safival != null, "Unhandled subsequent address family " + safi);
final SendReceive sendReceive = addressFamily.getSendReceive();
checkArgument(sendReceive != null, "Unhandled Send/Receive value");
capBuffer.writeShort(afival).writeByte(safival).writeByte(sendReceive.getIntValue());
}
CapabilityUtil.formatCapability(CODE, capBuffer, byteAggregator);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies in project bgpcep by opendaylight.
the class AddPathCapabilityHandler method parseCapability.
@Override
public CParameters parseCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
final List<AddressFamilies> families = new ArrayList<>();
while (buffer.isReadable()) {
final int afiVal = buffer.readUnsignedShort();
final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
if (afi == null) {
throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
}
final int safiVal = buffer.readUnsignedByte();
final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
if (safi == null) {
throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
}
final SendReceive sendReceive = SendReceive.forValue(buffer.readUnsignedByte());
if (sendReceive != null) {
families.add(new AddressFamiliesBuilder().setAfi(afi).setSafi(safi).setSendReceive(sendReceive).build());
}
}
return new CParametersBuilder().addAugmentation(new CParameters1Builder().setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(families).build()).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies in project bgpcep by opendaylight.
the class AddPathCapabilityHandlerTest method testCapabilityHandler.
@Test
public void testCapabilityHandler() throws BGPDocumentedException, BGPParsingException {
final List<AddressFamilies> family = new ArrayList<>();
family.add(new AddressFamiliesBuilder().setAfi(AddPathCapabilityHandlerTest.AFI).setSafi(AddPathCapabilityHandlerTest.SAFI).setSendReceive(SendReceive.forValue(1)).build());
final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(new CParameters1Builder().setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(family).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer(6);
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safiRegistry);
handler.serializeCapability(capabilityToSerialize, bytes);
assertArrayEquals(this.serializedBytes, bytes.array());
final CParameters newCaps = handler.parseCapability(this.parseCorrectBytes);
assertEquals(capabilityToSerialize.hashCode(), newCaps.hashCode());
}
Aggregations