Search in sources :

Example 11 with VtepsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey in project genius by opendaylight.

the class TepCommandHelper method isInCache.

// deletes from ADD-cache if it exists.
public boolean isInCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask, String gatewayIp, String transportZone, CommandSession session) {
    boolean exists = false;
    final VtepsKey vtepkey = new VtepsKey(dpnId, portName);
    IpAddress ipAddressObj = IpAddressBuilder.getDefaultInstance(ipAddress);
    IpPrefix subnetMaskObj = IpPrefixBuilder.getDefaultInstance(subnetMask);
    IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
    if (gatewayIp != null) {
        gatewayIpObj = IpAddressBuilder.getDefaultInstance(gatewayIp);
    } else {
        LOG.debug("gateway is null");
    }
    SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
    Vteps vtepCli = new VtepsBuilder().setDpnId(dpnId).setIpAddress(ipAddressObj).setKey(vtepkey).setPortname(portName).build();
    SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
    if (transportZonesHashMap.containsKey(transportZone)) {
        Map<SubnetObject, List<Vteps>> subVtepMapTemp = transportZonesHashMap.get(transportZone);
        if (subVtepMapTemp.containsKey(subObCli)) {
            // if Subnet exists
            List<Vteps> vtepListTemp = subVtepMapTemp.get(subObCli);
            if (vtepListTemp.contains(vtepCli)) {
                // return true if tzones has vtep
                exists = true;
                vtepListTemp.remove(vtepCli);
                if (vtepListTemp.size() == 0) {
                    subVtepMapTemp.remove(subObCli);
                    if (subVtepMapTemp.size() == 0) {
                        transportZonesHashMap.remove(transportZone);
                    }
                }
            } else if (session != null) {
                session.getConsole().println("Vtep " + "has not been configured");
            }
        }
    }
    return exists;
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) VtepsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) List(java.util.List) ArrayList(java.util.ArrayList) VtepsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsBuilder)

Example 12 with VtepsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey in project genius by opendaylight.

the class TepCommandHelper method deleteVtep.

@SuppressWarnings("checkstyle:IllegalCatch")
public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask, String gatewayIp, String transportZone, CommandSession session) throws TepException {
    IpAddress ipAddressObj = null;
    IpAddress gatewayIpObj = null;
    IpPrefix subnetMaskObj = null;
    final VtepsKey vtepkey = new VtepsKey(dpnId, portName);
    try {
        ipAddressObj = IpAddressBuilder.getDefaultInstance(ipAddress);
        gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
        if (!("null".equals(gatewayIp)) || ("0.0.0.0".equals(gatewayIp)) && (gatewayIp != null)) {
            gatewayIpObj = IpAddressBuilder.getDefaultInstance(gatewayIp);
        } else {
            LOG.debug("gateway is null");
            gatewayIp = null;
        }
    } catch (RuntimeException e) {
        handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
        return;
    }
    try {
        subnetMaskObj = IpPrefixBuilder.getDefaultInstance(subnetMask);
    } catch (Exception e) {
        handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
        return;
    }
    if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
        handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
        return;
    }
    SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
    Vteps vtepCli = null;
    Subnets subCli = null;
    InstanceIdentifier<Vteps> vpath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(Vteps.class, vtepkey).build();
    // check if present in tzones and delete from cache
    boolean existsInCache = isInCache(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone, session);
    if (!existsInCache) {
        Optional<Vteps> vtepOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, vpath, dataBroker);
        if (vtepOptional.isPresent()) {
            vtepCli = vtepOptional.get();
            if (vtepCli.getIpAddress().equals(ipAddressObj)) {
                InstanceIdentifier<Subnets> spath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).build();
                Optional<Subnets> subOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, spath, dataBroker);
                if (subOptional.isPresent()) {
                    subCli = subOptional.get();
                    if (subCli.getGatewayIp().equals(gatewayIpObj) && subCli.getVlanId().equals(vlanId)) {
                        vtepDelCommitList.add(vtepCli);
                    } else if (session != null) {
                        session.getConsole().println("vtep with this vlan or gateway doesnt exist");
                    }
                }
            } else if (session != null) {
                session.getConsole().println("Vtep with this ipaddress doesnt exist");
            }
        } else if (session != null) {
            session.getConsole().println("Vtep Doesnt exist");
        }
    }
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) VtepsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) 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) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Aggregations

VtepsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey)12 SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey)11 TransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)9 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)9 VtepsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsBuilder)7 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)6 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)5 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)4 TransportZoneBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder)4 SubnetsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsBuilder)4 ArrayList (java.util.ArrayList)3 StateTunnelList (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList)3 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)3 TepsInNotHostedTransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZoneKey)3 UnknownVteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps)3 DeviceVtepsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsBuilder)3 DeviceVtepsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey)3 List (java.util.List)2 HwVtep (org.opendaylight.genius.itm.confighelpers.HwVtep)2 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)2