Search in sources :

Example 21 with Elements

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project openflowplugin by opendaylight.

the class MessageFactoryTest method testCreateHelloInputWithElements.

@Test
public void testCreateHelloInputWithElements() {
    short highestVersion = (short) 0x04;
    long xid = 42L;
    Boolean[] expectedVersionBitmap = new Boolean[] { false, true, false, false, true };
    HelloInput helloMsg = MessageFactory.createHelloInput(highestVersion, xid, OFConstants.VERSION_ORDER);
    Assert.assertEquals(highestVersion, helloMsg.getVersion().shortValue());
    Assert.assertEquals(xid, helloMsg.getXid().longValue());
    Assert.assertEquals(1, helloMsg.getElements().size());
    Elements actualElement = helloMsg.getElements().get(0);
    Assert.assertEquals(HelloElementType.VERSIONBITMAP, actualElement.getType());
    Assert.assertArrayEquals(expectedVersionBitmap, actualElement.getVersionBitmap().toArray(new Boolean[0]));
}
Also used : HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) Elements(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements) Test(org.junit.Test)

Example 22 with Elements

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project genius by opendaylight.

the class OvsdbTepRemoveConfigHelper method removeTepReceivedFromOvsdb.

/**
 * Removes the TEP from ITM configuration/operational Datastore in one of the following cases.
 * 1) default transport zone
 * 2) Configured transport zone
 * 3) Unhosted transport zone
 * Function checks for above three cases and calls other sub-function to remove the TEP
 *
 * @param tepIp TEP-IP address in string
 * @param strDpnId bridge datapath ID in string
 * @param tzName transport zone name in string
 * @param dataBroker data broker handle to perform operations on config/operational datastore
 * @param wrTx WriteTransaction object
 */
public static void removeTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName, DataBroker dataBroker, WriteTransaction wrTx) {
    BigInteger dpnId = BigInteger.valueOf(0);
    LOG.trace("Remove TEP: TEP-IP: {}, TZ name: {}, DPID: {}", tepIp, tzName, strDpnId);
    if (strDpnId != null && !strDpnId.isEmpty()) {
        dpnId = MDSALUtil.getDpnId(strDpnId);
    }
    // Get tep IP
    IpAddress tepIpAddress = IpAddressBuilder.getDefaultInstance(tepIp);
    TransportZone transportZone = null;
    // Case: TZ name is not given from OVS's other_config parameters.
    if (tzName == null) {
        tzName = ITMConstants.DEFAULT_TRANSPORT_ZONE;
        // add TEP into default-TZ
        transportZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
        if (transportZone == null) {
            LOG.error("Error: default-transport-zone is not yet created.");
            return;
        }
        LOG.trace("Remove TEP from default-transport-zone.");
    } else {
        // Case: Add TEP into corresponding TZ created from Northbound.
        transportZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
        if (transportZone == null) {
            // Case: TZ is not configured from Northbound, then add TEP into
            // "teps-in-not-hosted-transport-zone"
            LOG.trace("Removing TEP from teps-in-not-hosted-transport-zone list.");
            removeUnknownTzTepFromTepsNotHosted(tzName, tepIpAddress, dpnId, dataBroker, wrTx);
            return;
        } else {
            LOG.trace("Remove TEP from transport-zone already configured by Northbound.");
        }
    }
    // Remove TEP from (default transport-zone) OR (transport-zone already configured by Northbound)
    // Get subnet list of corresponding TZ created from Northbound.
    List<Subnets> subnetList = transportZone.getSubnets();
    if (subnetList == null || subnetList.isEmpty()) {
        LOG.trace("No subnet list in transport-zone. Nothing to do.");
    } else {
        IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
        List<Vteps> vtepList = null;
        // subnet list already exists case; check for dummy-subnet
        for (Subnets subnet : subnetList) {
            if (subnet.getKey().getPrefix().equals(subnetMaskObj)) {
                LOG.trace("Subnet exists in the subnet list of transport-zone {}.", tzName);
                // get vtep list of existing subnet
                vtepList = subnet.getVteps();
                break;
            }
        }
        if (vtepList == null || vtepList.isEmpty()) {
            // case: vtep list does not exist or it has no elements
            LOG.trace("No vtep list in subnet list of transport-zone. Nothing to do.");
        } else {
            // case: vtep list has elements
            boolean vtepFound = false;
            Vteps oldVtep = null;
            for (Vteps vtep : vtepList) {
                if (vtep.getDpnId().equals(dpnId)) {
                    vtepFound = true;
                    oldVtep = vtep;
                    break;
                }
            }
            if (vtepFound) {
                // vtep is found, update it with tep-ip
                LOG.trace("Remove TEP from vtep list in subnet list of transport-zone.");
                dpnId = oldVtep.getDpnId();
                String portName = oldVtep.getPortname();
                removeVtepFromTZConfig(subnetMaskObj, tzName, dpnId, portName, wrTx);
            } else {
                LOG.trace("TEP is not found in the vtep list in subnet list of transport-zone. Nothing to do.");
            }
        }
    }
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) UnknownVteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) TepsInNotHostedTransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)

Example 23 with Elements

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project genius by opendaylight.

the class OvsdbTepAddConfigHelper method addTepReceivedFromOvsdb.

/**
 * Adds the TEP into ITM configuration/operational Datastore in one of the following cases.
 * 1) default transport zone
 * 2) Configured transport zone
 * 3) Unhosted transport zone
 *
 * @param tepIp TEP-IP address in string
 * @param strDpnId bridge datapath ID in string
 * @param tzName transport zone name in string
 * @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
 * @param dataBroker data broker handle to perform operations on config/operational datastore
 * @param wrTx WriteTransaction object
 */
public static void addTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName, boolean ofTunnel, DataBroker dataBroker, WriteTransaction wrTx) {
    BigInteger dpnId = BigInteger.valueOf(0);
    if (strDpnId != null && !strDpnId.isEmpty()) {
        dpnId = MDSALUtil.getDpnId(strDpnId);
    }
    // Get tep IP
    IpAddress tepIpAddress = IpAddressBuilder.getDefaultInstance(tepIp);
    TransportZone tzone = null;
    // Case: TZ name is not given with OVS TEP.
    if (tzName == null) {
        tzName = ITMConstants.DEFAULT_TRANSPORT_ZONE;
        // add TEP into default-TZ
        tzone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
        if (tzone == null) {
            LOG.error("Error: default-transport-zone is not yet created.");
            return;
        }
        LOG.trace("Add TEP into default-transport-zone.");
    } else {
        // Case: Add TEP into corresponding TZ created from Northbound.
        tzone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
        if (tzone == null) {
            // Case: TZ is not configured from Northbound, then add TEP into "teps-in-not-hosted-transport-zone"
            LOG.trace("Adding TEP with unknown TZ into teps-in-not-hosted-transport-zone.");
            addUnknownTzTepIntoTepsNotHosted(tzName, tepIpAddress, dpnId, ofTunnel, dataBroker, wrTx);
            return;
        } else {
            LOG.trace("Add TEP into transport-zone already configured by Northbound.");
        }
    }
    // Get subnet list of corresponding TZ created from Northbound.
    List<Subnets> subnetList = tzone.getSubnets();
    String portName = ITMConstants.DUMMY_PORT;
    IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
    if (subnetList == null || subnetList.isEmpty()) {
        if (subnetList == null) {
            subnetList = new ArrayList<>();
        }
        List<Vteps> vtepList = new ArrayList<>();
        LOG.trace("Add TEP in transport-zone when no subnet-list.");
        addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
    } else {
        List<Vteps> vtepList = null;
        // subnet list already exists case; check for dummy-subnet
        for (Subnets subnet : subnetList) {
            if (subnet.getKey().getPrefix().equals(subnetMaskObj)) {
                LOG.trace("Subnet exists in the subnet list of transport-zone {}.", tzName);
                // get vtep list of existing subnet
                vtepList = subnet.getVteps();
                break;
            }
        }
        if (vtepList == null || vtepList.isEmpty()) {
            // case: vtep list does not exist or it has no elements
            if (vtepList == null) {
                vtepList = new ArrayList<>();
            }
            LOG.trace("Add TEP in transport-zone when no vtep-list for specific subnet.");
            addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
        } else {
            // case: vtep list has elements
            boolean vtepFound = false;
            Vteps oldVtep = null;
            for (Vteps vtep : vtepList) {
                if (vtep.getDpnId().equals(dpnId)) {
                    vtepFound = true;
                    oldVtep = vtep;
                    // get portName of existing vtep
                    portName = vtep.getPortname();
                    break;
                }
            }
            if (!vtepFound) {
                addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
            } else {
                // vtep is found, update it with tep-ip
                vtepList.remove(oldVtep);
                addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
            }
        }
    }
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) UnknownVteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) TepsInNotHostedTransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)

Example 24 with Elements

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements in project genius by opendaylight.

the class OvsdbTepAddConfigHelper method addUnknownTzTepIntoTepsNotHosted.

/**
 * Adds the TEP into Vtep list in the subnet list in the transport zone list
 * from ITM operational Datastore by merge operation with write transaction.
 *
 * @param tzName transport zone name in string
 * @param tepIpAddress TEP IP address in IpAddress object
 * @param dpid bridge datapath ID in BigInteger
 * @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
 * @param dataBroker data broker handle to perform operations on operational datastore
 * @param wrTx WriteTransaction object
 */
protected static void addUnknownTzTepIntoTepsNotHosted(String tzName, IpAddress tepIpAddress, BigInteger dpid, boolean ofTunnel, DataBroker dataBroker, WriteTransaction wrTx) {
    List<UnknownVteps> vtepList = null;
    TepsInNotHostedTransportZone tepsInNotHostedTransportZone = ItmUtils.getUnknownTransportZoneFromITMOperDS(tzName, dataBroker);
    if (tepsInNotHostedTransportZone == null) {
        LOG.trace("Unhosted TransportZone ({}) does not exist in OperDS.", tzName);
        vtepList = new ArrayList<>();
        addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
    } else {
        vtepList = tepsInNotHostedTransportZone.getUnknownVteps();
        if (vtepList == null || vtepList.isEmpty()) {
            // case: vtep list does not exist or it has no elements
            if (vtepList == null) {
                vtepList = new ArrayList<>();
            }
            LOG.trace("Add TEP into unhosted TZ ({}) when no vtep-list in the TZ.", tzName);
            addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
        } else {
            // case: vtep list has elements
            boolean vtepFound = false;
            UnknownVteps oldVtep = null;
            for (UnknownVteps vtep : vtepList) {
                if (vtep.getDpnId().equals(dpid)) {
                    vtepFound = true;
                    oldVtep = vtep;
                    break;
                }
            }
            if (!vtepFound) {
                addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
            } else {
                // vtep is found, update it with tep-ip
                vtepList.remove(oldVtep);
                addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
            }
        }
    }
}
Also used : TepsInNotHostedTransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone) UnknownVteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps)

Aggregations

Elements (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)8 ElementsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder)8 ByteBuf (io.netty.buffer.ByteBuf)6 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)4 UnknownVteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps)4 HelloMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage)4 HelloInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput)3 HelloInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder)3 BigInteger (java.math.BigInteger)2 DefaultDeserializerFactoryTest (org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)2 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)2 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets)2 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)1