Search in sources :

Example 1 with AddressFamilies

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.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;
    }
    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 AddressFamilies

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.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(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.neighbors.AddressFamilies) AddressFamiliesKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.AddressFamiliesKey) Neighbors(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) AddressFamiliesBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.AddressFamiliesBuilder) NeighborsKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NeighborsKey) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 3 with AddressFamilies

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.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(CParameters1.class, new CParameters1Builder().setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(families).build()).build()).build();
}
Also used : ArrayList(java.util.ArrayList) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) SendReceive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies) AddPathCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapabilityBuilder) AddressFamiliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamiliesBuilder)

Example 4 with AddressFamilies

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.AddressFamilies in project bgpcep by opendaylight.

the class AddPathCapabilityHandler method serializeCapability.

@Override
public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
    if ((capability.getAugmentation(CParameters1.class) == null) || (capability.getAugmentation(CParameters1.class).getAddPathCapability() == null)) {
        return;
    }
    final AddPathCapability addPathCap = capability.getAugmentation(CParameters1.class).getAddPathCapability();
    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);
            Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
            capBuffer.writeShort(afival);
            final Class<? extends SubsequentAddressFamily> safi = addressFamily.getSafi();
            final Integer safival = this.safiReg.numberForClass(safi);
            Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
            capBuffer.writeByte(safival);
            final SendReceive sendReceive = addressFamily.getSendReceive();
            Preconditions.checkArgument(sendReceive != null, "Unhandled Send/Receive value");
            capBuffer.writeByte(sendReceive.getIntValue());
        }
        CapabilityUtil.formatCapability(CODE, capBuffer, byteAggregator);
    }
}
Also used : AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies) AddPathCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapability) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) ByteBuf(io.netty.buffer.ByteBuf) SendReceive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive)

Example 5 with AddressFamilies

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.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(CParameters1.class, 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());
}
Also used : CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) AddPathCapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.AddPathCapabilityHandler) AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies) AddPathCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapabilityBuilder) ArrayList(java.util.ArrayList) AddressFamiliesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamiliesBuilder) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)11 AddressFamilies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamilies)11 CParameters1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1)7 Test (org.junit.Test)6 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)6 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder)6 AddPathCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapabilityBuilder)6 AddressFamiliesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.add.path.capability.AddressFamiliesBuilder)6 ByteBuf (io.netty.buffer.ByteBuf)5 CParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters)5 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType)5 AddPathCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.AddPathCapabilityHandler)4 AfiSafi (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi)3 Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)3 AddressFamilies (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.AddressFamilies)3 SendReceive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.SendReceive)3 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)3 List (java.util.List)2 Set (java.util.Set)2 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)2