X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=ovs-driver%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Funimgr%2Fmef%2Fnrp%2Fovs%2Factivator%2FOvsActivatorHelper.java;h=2f8e52d0e27f8751e6896ddf120c00ddfbb2e899;hb=92d3d5c52623c244d4792b4c49febbaaaa8efe2a;hp=b2e67a682122355a1c3fd0f3444b2c0783cd4d33;hpb=18c863bbc170e5774e71bbf5b241e87ce909fdce;p=unimgr.git diff --git a/ovs-driver/src/main/java/org/opendaylight/unimgr/mef/nrp/ovs/activator/OvsActivatorHelper.java b/ovs-driver/src/main/java/org/opendaylight/unimgr/mef/nrp/ovs/activator/OvsActivatorHelper.java index b2e67a68..2f8e52d0 100644 --- a/ovs-driver/src/main/java/org/opendaylight/unimgr/mef/nrp/ovs/activator/OvsActivatorHelper.java +++ b/ovs-driver/src/main/java/org/opendaylight/unimgr/mef/nrp/ovs/activator/OvsActivatorHelper.java @@ -7,24 +7,27 @@ */ package org.opendaylight.unimgr.mef.nrp.ovs.activator; +import static java.util.stream.Collectors.toSet; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + import java.util.List; +import java.util.Optional; +import java.util.Set; import org.opendaylight.unimgr.mef.nrp.api.EndPoint; import org.opendaylight.unimgr.mef.nrp.common.ResourceNotAvailableException; -import org.opendaylight.unimgr.mef.nrp.ovs.exception.VlanNotSetException; import org.opendaylight.unimgr.mef.nrp.ovs.transaction.TopologyTransaction; -import org.opendaylight.unimgr.utils.NullAwareDatastoreGetter; -import org.opendaylight.yang.gen.v1.urn.mef.yang.nrm.connectivity.rev171221.carrier.eth.connectivity.end.point.resource.IngressBwpFlow; -import org.opendaylight.yang.gen.v1.urn.mef.yang.nrp._interface.rev171221.nrp.connectivity.service.end.point.attrs.NrpCarrierEthConnectivityEndPointResource; +import org.opendaylight.unimgr.mef.nrp.ovs.util.NullAwareDatastoreGetter; +import org.opendaylight.yang.gen.v1.urn.mef.yang.nrm.connectivity.rev180321.carrier.eth.connectivity.end.point.resource.IngressBwpFlow; +import org.opendaylight.yang.gen.v1.urn.mef.yang.nrp._interface.rev180321.nrp.connectivity.service.end.point.attrs.NrpCarrierEthConnectivityEndPointResource; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - /** * Helper class for OvsDriver activation. * @@ -36,9 +39,11 @@ class OvsActivatorHelper { private String tpName; private BiMap portMap; - private static final String CTAG_VLAN_ID_NOT_SET_ERROR_MESSAGE = "C-Tag VLAN Id not set for End Point '%s'."; - private static final String INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE = "Ingress bwp flow is not set for End Point '%s'."; + private static final String INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE + = "Ingress bwp flow is not set for End Point '%s'."; private static final String ATTRS_NOT_SET_ERROR_MESSAGE = "End Point '%s' does not have '%s' set."; + private static final String VLANS_DIFFERENT_ERROR_MESSAFE + = "External VLANs defined on end points has to be the same or not defined. Current values %s"; private static final Logger LOG = LoggerFactory.getLogger(OvsActivatorHelper.class); @@ -46,25 +51,31 @@ class OvsActivatorHelper { OvsActivatorHelper(TopologyTransaction topologyTransaction, EndPoint endPoint) { this.nodes = topologyTransaction.readNodes(); this.endPoint = endPoint; - tpName = getPortName(endPoint.getEndpoint().getServiceInterfacePoint().getValue()); - this.portMap = createPortMap(nodes); + tpName = getPortName(endPoint.getEndpoint().getServiceInterfacePoint().getServiceInterfacePointId().getValue()); + this.portMap = createPortMap(); + } + + private OvsActivatorHelper(EndPoint endPoint) { + this.endPoint = endPoint; } /** - * Returns VLAN Id of the service + * Returns VLAN Id of the endPoint. * - * @return Integer with VLAN Id + * @return int with VLAN Id */ - int getCeVlanId() throws ResourceNotAvailableException { - - if ( (endPoint.getAttrs() != null) && (endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource() != null) ) { - NrpCarrierEthConnectivityEndPointResource attr = endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource(); - if ( (attr.getCeVlanIdListAndUntag()!=null) && !(attr.getCeVlanIdListAndUntag().getVlanId().isEmpty()) ) { + Optional getCeVlanId() throws ResourceNotAvailableException { + + if ((endPoint.getAttrs() != null) + && (endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource() != null)) { + NrpCarrierEthConnectivityEndPointResource attr + = endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource(); + if ((attr.getCeVlanIdListAndUntag() != null) + && !(attr.getCeVlanIdListAndUntag().getVlanId().isEmpty())) { //for now we support only one CE VLAN - return attr.getCeVlanIdListAndUntag().getVlanId().get(0).getVlanId().getValue().intValue(); + return Optional.of(attr.getCeVlanIdListAndUntag().getVlanId().get(0).getVlanId().getValue().intValue()); } else { - LOG.warn(String.format(CTAG_VLAN_ID_NOT_SET_ERROR_MESSAGE, tpName)); - throw new VlanNotSetException(String.format(CTAG_VLAN_ID_NOT_SET_ERROR_MESSAGE, tpName)); + return Optional.empty(); //port-base service } } else { String className = NrpCarrierEthConnectivityEndPointResource.class.toString(); @@ -73,25 +84,6 @@ class OvsActivatorHelper { } } - /** - * Returns VLAN Id to be used internally in OvSwitch network - * - * @return Integer with VLAN Id - */ - int getInternalVlanId() throws ResourceNotAvailableException { - - return getCeVlanId(); -// VlanUtils vlanUtils = new VlanUtils(nodes); -// Disable VLAN pool, refactor in the future -// if (vlanUtils.isVlanInUse(serviceVlanId)) { -// LOG.debug("VLAN ID = '" + serviceVlanId + "' already in use."); -// return vlanUtils.generateVlanID(); -// } else { -// LOG.debug("VLAN ID = '" + serviceVlanId + "' not in use."); -// return serviceVlanId; -// } - } - /** * Returns port name in openflow plugin naming convention (e.g. openflow:1:4) * @@ -102,61 +94,80 @@ class OvsActivatorHelper { } /** - * Returns port name for specifiec port name in openflow convention + * Returns port name for specifiec port name in openflow convention. * @param openFlowPortName port in openflow plugin naming convention * @return String with port name */ String getTpNameFromOpenFlowPortName(String openFlowPortName) { - return portMap.inverse().get(openFlowPortName); + return portMap.inverse().get(openFlowPortName); } - private BiMap createPortMap(List> nodes) { - BiMap portMap = HashBiMap.create(); + private BiMap createPortMap() { + BiMap result = HashBiMap.create(); for (NullAwareDatastoreGetter node : nodes) { if (node.get().isPresent()) { for (NodeConnector nodeConnector : node.get().get().getNodeConnector()) { String ofName = nodeConnector.getId().getValue(); - FlowCapableNodeConnector flowCapableNodeConnector = nodeConnector.getAugmentation(FlowCapableNodeConnector.class); + FlowCapableNodeConnector flowCapableNodeConnector + = nodeConnector.augmentation(FlowCapableNodeConnector.class); String name = flowCapableNodeConnector.getName(); - portMap.put(name, ofName); + result.put(name, ofName); } } } - return portMap; + return result; } protected static String getPortName(String sip) { String[] tab = sip.split(":"); - return tab[tab.length-1]; + return tab[tab.length - 1]; } - public long getQosMinRate() throws ResourceNotAvailableException { - if ( (endPoint.getAttrs() != null) && (endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource() != null) ) { - NrpCarrierEthConnectivityEndPointResource attr = endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource(); - IngressBwpFlow ingressBwpFlow = attr.getIngressBwpFlow(); - if(ingressBwpFlow != null) { - //TODO add validation - return ingressBwpFlow.getCir().getValue(); - } else { - LOG.warn(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); - throw new ResourceNotAvailableException(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); - } - } - return 0; - } - - public long getQosMaxRate() throws ResourceNotAvailableException { - if ( (endPoint.getAttrs() != null) && (endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource() != null) ) { - NrpCarrierEthConnectivityEndPointResource attr = endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource(); - IngressBwpFlow ingressBwpFlow = attr.getIngressBwpFlow(); - if(ingressBwpFlow != null) { - //TODO add validation - return ingressBwpFlow.getCir().getValue() + ingressBwpFlow.getEir().getValue(); - } else { - LOG.warn(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); - throw new ResourceNotAvailableException(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); - } - } - return 0; - } + public long getQosMinRate() throws ResourceNotAvailableException { + IngressBwpFlow ingressBwpFlow = getIngressBwpFlow(); + if (ingressBwpFlow != null) { + //TODO add validation + return ingressBwpFlow.getCir().getValue(); + } + + LOG.warn(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); + throw new ResourceNotAvailableException(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); + } + + public long getQosMaxRate() throws ResourceNotAvailableException { + + IngressBwpFlow ingressBwpFlow = getIngressBwpFlow(); + if (ingressBwpFlow != null) { + //TODO add validation + return ingressBwpFlow.getCir().getValue() + ingressBwpFlow.getEir().getValue(); + } + + LOG.warn(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); + throw new ResourceNotAvailableException(String.format(INGRESS_BWP_FLOW_NOT_SET_ERROR_MESSAGE, tpName)); + } + + private IngressBwpFlow getIngressBwpFlow() { + if ((endPoint.getAttrs() == null) + || (endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource() == null)) { + return null; + } + return endPoint.getAttrs().getNrpCarrierEthConnectivityEndPointResource().getIngressBwpFlow(); + } + + protected boolean isIBwpConfigured() { + return getIngressBwpFlow() != null; + } + + public static void validateExternalVLANs(List endPoints) throws ResourceNotAvailableException { + Set vlans = endPoints.stream().map(ep -> { + try { + return new OvsActivatorHelper(ep).getCeVlanId(); + } catch (ResourceNotAvailableException e) { + return Optional.empty(); + } + }).filter(i -> i.isPresent()).collect(toSet()); + if (vlans.size() > 1) { + throw new ResourceNotAvailableException(String.format(VLANS_DIFFERENT_ERROR_MESSAFE, vlans.toString())); + } + } }