Remove openstack4j NetworkType due to unsupport of GENEVE tunnel
Change-Id: Id3579b706480114b076fbe867040b9bf8c2c738f
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/OpenstackNetwork.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/OpenstackNetwork.java
new file mode 100644
index 0000000..149b607
--- /dev/null
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/OpenstackNetwork.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacknetworking.api;
+
+/**
+ * Representation of augmented openstack network.
+ */
+public interface OpenstackNetwork {
+
+ /**
+ * Lists of network type.
+ */
+ enum Type {
+
+ /**
+ * LOCAL typed network.
+ */
+ LOCAL,
+
+ /**
+ * FLAT typed network.
+ */
+ FLAT,
+
+ /**
+ * VLAN typed virtual network.
+ */
+ VLAN,
+
+ /**
+ * VXLAN typed virtual network.
+ */
+ VXLAN,
+
+ /**
+ * GRE typed virtual network.
+ */
+ GRE,
+
+ /**
+ * GENEVE typed virtual network.
+ */
+ GENEVE
+ }
+
+ /**
+ * Returns the openstack network ID of the augmented network.
+ *
+ * @return openstack network ID
+ */
+ String networkId();
+
+ /**
+ * Returns openstack network type.
+ *
+ * @return oepnstack network type
+ */
+ Type type();
+}
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/OpenstackNetworkService.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/OpenstackNetworkService.java
index 71d9bb1..279bbbd 100644
--- a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/OpenstackNetworkService.java
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/OpenstackNetworkService.java
@@ -19,6 +19,7 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.event.ListenerService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.openstack4j.model.network.ExternalGateway;
import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.Port;
@@ -40,6 +41,14 @@
Network network(String networkId);
/**
+ * Returns the network type with the supplied network ID.
+ *
+ * @param networkId network id
+ * @return openstack network type
+ */
+ Type networkType(String networkId);
+
+ /**
* Returns all networks registered in the service.
*
* @return set of networks
@@ -148,14 +157,6 @@
IpPrefix ipPrefix(String portId);
/**
- * Returns network type with supplied network ID.
- *
- * @param netId openstack network id
- * @return network type
- */
- String networkType(String netId);
-
- /**
* Returns gateway ip address with supplied port ID.
*
* @param portId openstack port id
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java
index 01a574d..456019a 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java
@@ -30,7 +30,6 @@
import java.util.List;
import java.util.stream.Collectors;
-import static org.onosproject.cli.AbstractShellCommand.get;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson;
@@ -53,7 +52,7 @@
if (outputJson()) {
print("%s", json(networks));
} else {
- print(FORMAT, "ID", "Name", "Network Mode", "SegId", "Subnets", "HostRoutes");
+ print(FORMAT, "ID", "Name", "Type", "SegId", "Subnets", "HostRoutes");
for (Network net: networks) {
List<Subnet> subnets = service.subnets().stream()
.filter(subnet -> subnet.getNetworkId().equals(net.getId()))
@@ -71,7 +70,7 @@
print(FORMAT, net.getId(),
net.getName(),
- net.getNetworkType().toString(),
+ service.networkType(net.getId()).toString(),
net.getProviderSegID(),
subnets.isEmpty() ? "" : subnetsString,
hostRoutes.isEmpty() ? "" : hostRoutes);
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DefaultOpenstackNetwork.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DefaultOpenstackNetwork.java
new file mode 100644
index 0000000..124f912
--- /dev/null
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DefaultOpenstackNetwork.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstacknetworking.impl;
+
+import com.google.common.base.MoreObjects;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork;
+
+import java.util.Objects;
+
+/**
+ * Default implementation of augmented network.
+ */
+public final class DefaultOpenstackNetwork implements OpenstackNetwork {
+
+ private final String networkId;
+ private final Type type;
+
+ /**
+ * A default constructor for openstack network implementation class.
+ *
+ * @param networkId network ID
+ * @param type network type
+ */
+ public DefaultOpenstackNetwork(String networkId, Type type) {
+ this.networkId = networkId;
+ this.type = type;
+ }
+
+ @Override
+ public String networkId() {
+ return networkId;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("networkId", networkId)
+ .add("type", type)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultOpenstackNetwork) {
+ DefaultOpenstackNetwork that = (DefaultOpenstackNetwork) obj;
+ return Objects.equals(networkId, that.networkId) &&
+ Objects.equals(type, that.type);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(networkId, type);
+ }
+}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
index e7cda54..98bd413 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
@@ -35,6 +35,8 @@
import org.onosproject.net.packet.PacketService;
import org.onosproject.openstacknetworking.api.Constants;
import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService;
import org.onosproject.openstacknetworking.api.OpenstackNetworkEvent;
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
@@ -47,11 +49,10 @@
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
-import org.openstack4j.model.common.IdEntity;
+import org.onosproject.store.service.Versioned;
import org.openstack4j.model.network.ExternalGateway;
import org.openstack4j.model.network.IP;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Router;
import org.openstack4j.model.network.Subnet;
@@ -63,6 +64,7 @@
import org.slf4j.Logger;
import java.nio.ByteBuffer;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
@@ -75,6 +77,12 @@
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
import static org.onosproject.openstacknetworking.api.Constants.DIRECT;
import static org.onosproject.openstacknetworking.api.Constants.PCISLOT;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GENEVE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.LOCAL;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
@@ -96,12 +104,16 @@
protected final Logger log = getLogger(getClass());
private static final String MSG_NETWORK = "OpenStack network %s %s";
+ private static final String MSG_NETWORK_TYPE = "OpenStack network type %s %s";
private static final String MSG_SUBNET = "OpenStack subnet %s %s";
private static final String MSG_PORT = "OpenStack port %s %s";
private static final String MSG_CREATED = "created";
private static final String MSG_UPDATED = "updated";
private static final String MSG_REMOVED = "removed";
+ private static final String ERR_NOT_FOUND = " does not exist";
+ private static final String ERR_DUPLICATE = " already exists";
+
private static final String ERR_NULL_NETWORK =
"OpenStack network cannot be null";
private static final String ERR_NULL_NETWORK_ID =
@@ -148,6 +160,7 @@
delegate = new InternalNetworkStoreDelegate();
private ConsistentMap<String, ExternalPeerRouter> externalPeerRouterMap;
+ private ConsistentMap<String, OpenstackNetwork> augmentedNetworkMap;
private static final KryoNamespace
SERIALIZER_EXTERNAL_PEER_ROUTER_MAP = KryoNamespace.newBuilder()
@@ -159,6 +172,14 @@
.register(VlanId.class)
.build();
+ private static final KryoNamespace
+ SERIALIZER_AUGMENTED_NETWORK_MAP = KryoNamespace.newBuilder()
+ .register(KryoNamespaces.API)
+ .register(OpenstackNetwork.Type.class)
+ .register(OpenstackNetwork.class)
+ .register(DefaultOpenstackNetwork.class)
+ .build();
+
private ApplicationId appId;
@@ -174,6 +195,12 @@
.withName("external-routermap")
.withApplicationId(appId)
.build();
+
+ augmentedNetworkMap = storageService.<String, OpenstackNetwork>consistentMapBuilder()
+ .withSerializer(Serializer.using(SERIALIZER_AUGMENTED_NETWORK_MAP))
+ .withName("augmented-networkmap")
+ .withApplicationId(appId)
+ .build();
}
@Deactivate
@@ -188,6 +215,14 @@
checkArgument(!Strings.isNullOrEmpty(osNet.getId()), ERR_NULL_NETWORK_ID);
osNetworkStore.createNetwork(osNet);
+
+ OpenstackNetwork finalAugmentedNetwork = buildAugmentedNetworkFromType(osNet);
+ augmentedNetworkMap.compute(osNet.getId(), (id, existing) -> {
+ final String error = osNet.getId() + ERR_DUPLICATE;
+ checkArgument(existing == null, error);
+ return finalAugmentedNetwork;
+ });
+
log.info(String.format(MSG_NETWORK, osNet.getName(), MSG_CREATED));
}
@@ -197,6 +232,14 @@
checkArgument(!Strings.isNullOrEmpty(osNet.getId()), ERR_NULL_NETWORK_ID);
osNetworkStore.updateNetwork(osNet);
+
+ OpenstackNetwork finalAugmentedNetwork = buildAugmentedNetworkFromType(osNet);
+ augmentedNetworkMap.compute(osNet.getId(), (id, existing) -> {
+ final String error = osNet.getId() + ERR_NOT_FOUND;
+ checkArgument(existing != null, error);
+ return finalAugmentedNetwork;
+ });
+
log.info(String.format(MSG_NETWORK, osNet.getId(), MSG_UPDATED));
}
@@ -212,6 +255,12 @@
if (osNet != null) {
log.info(String.format(MSG_NETWORK, osNet.getName(), MSG_REMOVED));
}
+
+ Versioned<OpenstackNetwork> augmentedNetwork = augmentedNetworkMap.remove(netId);
+ if (augmentedNetwork != null) {
+ log.info(String.format(MSG_NETWORK_TYPE,
+ augmentedNetwork.value().type(), MSG_REMOVED));
+ }
}
}
@@ -382,29 +431,28 @@
return Sets.newHashSet();
}
- Set<Network> networks = osNetworkStore.networks();
Set<String> networkIds = Sets.newConcurrentHashSet();
switch (type.toUpperCase()) {
case "FLAT" :
- networkIds = networks.stream()
- .filter(n -> n.getNetworkType() == NetworkType.FLAT)
- .map(IdEntity::getId).collect(Collectors.toSet());
+ networkIds = augmentedNetworkMap.asJavaMap().entrySet().stream()
+ .filter(e -> e.getValue().type() == FLAT)
+ .map(Map.Entry::getKey).collect(Collectors.toSet());
break;
case "VXLAN" :
- networkIds = networks.stream()
- .filter(n -> n.getNetworkType() == NetworkType.VXLAN)
- .map(IdEntity::getId).collect(Collectors.toSet());
+ networkIds = augmentedNetworkMap.asJavaMap().entrySet().stream()
+ .filter(e -> e.getValue().type() == Type.VXLAN)
+ .map(Map.Entry::getKey).collect(Collectors.toSet());
break;
case "GRE" :
- networkIds = networks.stream()
- .filter(n -> n.getNetworkType() == NetworkType.GRE)
- .map(IdEntity::getId).collect(Collectors.toSet());
+ networkIds = augmentedNetworkMap.asJavaMap().entrySet().stream()
+ .filter(e -> e.getValue().type() == Type.GRE)
+ .map(Map.Entry::getKey).collect(Collectors.toSet());
break;
case "VLAN" :
- networkIds = networks.stream()
- .filter(n -> n.getNetworkType() == NetworkType.VLAN)
- .map(IdEntity::getId).collect(Collectors.toSet());
+ networkIds = augmentedNetworkMap.asJavaMap().entrySet().stream()
+ .filter(e -> e.getValue().type() == VLAN)
+ .map(Map.Entry::getKey).collect(Collectors.toSet());
break;
default:
break;
@@ -633,12 +681,12 @@
}
@Override
- public String networkType(String netId) {
- Network network = network(netId);
+ public Type networkType(String netId) {
+ OpenstackNetwork network = augmentedNetworkMap.asJavaMap().get(netId);
checkNotNull(network);
- return network.getNetworkType().toString();
+ return network.type();
}
@Override
@@ -674,6 +722,35 @@
return network.getProviderSegID();
}
+ private OpenstackNetwork buildAugmentedNetworkFromType(Network osNet) {
+ OpenstackNetwork augmentedNetwork = null;
+ if (osNet.getNetworkType() == null) {
+ augmentedNetwork = new DefaultOpenstackNetwork(osNet.getId(), GENEVE);
+ } else {
+ switch (osNet.getNetworkType()) {
+ case FLAT:
+ augmentedNetwork = new DefaultOpenstackNetwork(osNet.getId(), FLAT);
+ break;
+ case VLAN:
+ augmentedNetwork = new DefaultOpenstackNetwork(osNet.getId(), VLAN);
+ break;
+ case VXLAN:
+ augmentedNetwork = new DefaultOpenstackNetwork(osNet.getId(), VXLAN);
+ break;
+ case GRE:
+ augmentedNetwork = new DefaultOpenstackNetwork(osNet.getId(), GRE);
+ break;
+ case LOCAL:
+ augmentedNetwork = new DefaultOpenstackNetwork(osNet.getId(), LOCAL);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return augmentedNetwork;
+ }
+
private boolean isNetworkInUse(String netId) {
return !subnets(netId).isEmpty() && !ports(netId).isEmpty();
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java
index 10abe3b..5a324ee 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingFloatingIpHandler.java
@@ -42,6 +42,7 @@
import org.onosproject.openstacknetworking.api.InstancePortEvent;
import org.onosproject.openstacknetworking.api.InstancePortListener;
import org.onosproject.openstacknetworking.api.OpenstackFlowRuleService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkEvent;
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
@@ -55,7 +56,6 @@
import org.onosproject.openstacknode.api.OpenstackNodeService;
import org.openstack4j.model.network.NetFloatingIP;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Port;
import org.openstack4j.openstack.networking.domain.NeutronFloatingIP;
import org.osgi.service.component.annotations.Activate;
@@ -80,6 +80,9 @@
import static org.onosproject.openstacknetworking.api.InstancePort.State.REMOVE_PENDING;
import static org.onosproject.openstacknetworking.api.InstancePortEvent.Type.OPENSTACK_INSTANCE_MIGRATION_ENDED;
import static org.onosproject.openstacknetworking.api.InstancePortEvent.Type.OPENSTACK_INSTANCE_MIGRATION_STARTED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN;
import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_PORT_PRE_REMOVE;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.associatedFloatingIp;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterForNetwork;
@@ -387,22 +390,23 @@
ExternalPeerRouter externalPeerRouter,
Set<OpenstackNode> gateways, boolean install) {
OpenstackNode cNode = osNodeService.node(instPort.deviceId());
+ Type netType = osNetworkService.networkType(osNet.getId());
if (cNode == null) {
final String error = String.format("Cannot find openstack node for device %s",
instPort.deviceId());
throw new IllegalStateException(error);
}
- if (osNet.getNetworkType() == NetworkType.VXLAN && cNode.dataIp() == null) {
+ if (netType == VXLAN && cNode.dataIp() == null) {
final String errorFormat = ERR_FLOW + "VXLAN mode is not ready for %s";
final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
- if (osNet.getNetworkType() == NetworkType.GRE && cNode.dataIp() == null) {
+ if (netType == GRE && cNode.dataIp() == null) {
final String errorFormat = ERR_FLOW + "GRE mode is not ready for %s";
final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
- if (osNet.getNetworkType() == NetworkType.VLAN && cNode.vlanIntf() == null) {
+ if (netType == VLAN && cNode.vlanIntf() == null) {
final String errorFormat = ERR_FLOW + "VLAN mode is not ready for %s";
final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
@@ -490,6 +494,7 @@
}
TrafficSelector selector = sBuilder.build();
+ Type netType = osNetworkService.networkType(osNet.getId());
osNodeService.completeNodes(GATEWAY).forEach(gNode -> {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
@@ -497,7 +502,7 @@
.setEthSrc(instPort.macAddress())
.setEthDst(externalPeerRouter.macAddress());
- if (osNet.getNetworkType().equals(NetworkType.VLAN)) {
+ if (netType == VLAN) {
tBuilder.popVlan();
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
index bde5efe..bc02119 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
@@ -48,6 +48,7 @@
import org.onosproject.openstacknetworking.api.InstancePortListener;
import org.onosproject.openstacknetworking.api.InstancePortService;
import org.onosproject.openstacknetworking.api.OpenstackFlowRuleService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService;
import org.onosproject.openstacknetworking.api.OpenstackRouterEvent;
import org.onosproject.openstacknetworking.api.OpenstackRouterListener;
@@ -59,7 +60,6 @@
import org.onosproject.openstacknode.api.OpenstackNodeService;
import org.openstack4j.model.network.ExternalGateway;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Router;
import org.openstack4j.model.network.RouterInterface;
import org.openstack4j.model.network.Subnet;
@@ -95,13 +95,14 @@
import static org.onosproject.openstacknetworking.api.Constants.ROUTING_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT_DEFAULT;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType;
import static org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
-import static org.openstack4j.model.network.NetworkType.FLAT;
/**
* Handles OpenStack router events.
@@ -219,8 +220,11 @@
Network network = osNetworkAdminService.network(
osNetworkAdminService.subnet(iface.getSubnetId())
.getNetworkId());
+ Type netType = osNetworkAdminService.networkType(
+ osNetworkAdminService.subnet(iface.getSubnetId())
+ .getNetworkId());
setRouterAdminRules(network.getProviderSegID(),
- network.getNetworkType(), !osRouter.isAdminStateUp());
+ netType, !osRouter.isAdminStateUp());
});
ExternalPeerRouter externalPeerRouter =
@@ -269,7 +273,10 @@
Network network = osNetworkAdminService.network(
osNetworkAdminService.subnet(iface.getSubnetId())
.getNetworkId());
- setRouterAdminRules(network.getProviderSegID(), network.getNetworkType(), false);
+ Type netType = osNetworkAdminService.networkType(
+ osNetworkAdminService.subnet(iface.getSubnetId())
+ .getNetworkId());
+ setRouterAdminRules(network.getProviderSegID(), netType, false);
});
}
@@ -285,8 +292,8 @@
if (!osRouter.isAdminStateUp()) {
Network network = osNetworkAdminService.network(osSubnet.getNetworkId());
- setRouterAdminRules(network.getProviderSegID(),
- network.getNetworkType(), true);
+ Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
+ setRouterAdminRules(network.getProviderSegID(), netType, true);
}
setInternalRoutes(osRouter, osSubnet, true);
@@ -310,8 +317,8 @@
if (!osRouter.isAdminStateUp()) {
Network network = osNetworkAdminService.network(osSubnet.getNetworkId());
- setRouterAdminRules(network.getProviderSegID(),
- network.getNetworkType(), false);
+ Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
+ setRouterAdminRules(network.getProviderSegID(), netType, false);
}
setInternalRoutes(osRouter, osSubnet, false);
@@ -326,11 +333,11 @@
private void setSourceNat(RouterInterface routerIface, boolean install) {
Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
+ Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
osNodeService.completeNodes(COMPUTE).forEach(cNode -> {
setRulesToGateway(cNode, osNet.getProviderSegID(),
- IpPrefix.valueOf(osSubnet.getCidr()), osNet.getNetworkType(),
- install);
+ IpPrefix.valueOf(osSubnet.getCidr()), netType, install);
});
if (useStatefulSnat) {
@@ -346,8 +353,9 @@
private void setStatefulSnatRules(RouterInterface routerIface, boolean install) {
Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
+ Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
- if (osNet.getNetworkType() == FLAT) {
+ if (netType == FLAT) {
return;
}
@@ -374,7 +382,7 @@
Long.parseLong(osNet.getProviderSegID()),
IpPrefix.valueOf(port.ipAddress(), VM_PREFIX),
port.deviceId(),
- osNet.getNetworkType(),
+ netType,
install));
setOvsNatIngressRule(gwNode.intgBridge(),
@@ -389,13 +397,14 @@
private void setReactiveSnatRules(RouterInterface routerIface, boolean install) {
Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
+ Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
osNodeService.completeNodes(GATEWAY)
.forEach(gwNode -> setRulesToController(
gwNode.intgBridge(),
osNet.getProviderSegID(),
IpPrefix.valueOf(osSubnet.getCidr()),
- osNet.getNetworkType(),
+ netType,
install));
}
@@ -493,7 +502,7 @@
network.getProviderSegID(),
osSubnet,
routableSubnets,
- NetworkType.VXLAN,
+ Type.VXLAN,
install));
}
@@ -510,7 +519,7 @@
network.getProviderSegID(),
osSubnet,
routableSubnets,
- NetworkType.GRE,
+ Type.GRE,
install));
}
@@ -527,12 +536,12 @@
network.getProviderSegID(),
osSubnet,
routableSubnets,
- NetworkType.VLAN,
+ VLAN,
install));
}
private void setInternalRoutes(Router osRouter, Subnet updatedSubnet, boolean install) {
- Network updatedNetwork = osNetworkAdminService.network(updatedSubnet.getNetworkId());
+ Type netType = osNetworkAdminService.networkType(updatedSubnet.getNetworkId());
Set<Subnet> routableSubnets = routableSubnets(osRouter, updatedSubnet.getId());
String updatedSegmentId = getSegmentId(updatedSubnet);
@@ -545,7 +554,7 @@
updatedSegmentId,
IpPrefix.valueOf(updatedSubnet.getCidr()),
IpPrefix.valueOf(updatedSubnet.getCidr()),
- updatedNetwork.getNetworkType(),
+ netType,
install
);
@@ -556,7 +565,7 @@
getSegmentId(subnet),
IpPrefix.valueOf(updatedSubnet.getCidr()),
IpPrefix.valueOf(subnet.getCidr()),
- updatedNetwork.getNetworkType(),
+ netType,
install
);
setInternalRouterRules(
@@ -565,7 +574,7 @@
updatedSegmentId,
IpPrefix.valueOf(subnet.getCidr()),
IpPrefix.valueOf(updatedSubnet.getCidr()),
- updatedNetwork.getNetworkType(),
+ netType,
install
);
});
@@ -615,7 +624,7 @@
private void setInternalRouterRules(DeviceId deviceId, String srcSegId, String dstSegId,
IpPrefix srcSubnet, IpPrefix dstSubnet,
- NetworkType networkType, boolean install) {
+ Type networkType, boolean install) {
switch (networkType) {
case VXLAN:
@@ -740,7 +749,7 @@
private void setRulesToGateway(OpenstackNode osNode,
String segmentId,
IpPrefix srcSubnet,
- NetworkType networkType,
+ Type networkType,
boolean install) {
OpenstackNode sourceNatGateway =
osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
@@ -774,7 +783,7 @@
switch (networkType) {
case VXLAN:
case GRE:
- PortNumber portNum = tunnelPortNumByNetType(networkType.name(), osNode);
+ PortNumber portNum = tunnelPortNumByNetType(networkType, osNode);
tBuilder.extension(buildExtension(
deviceService,
osNode.intgBridge(),
@@ -805,7 +814,7 @@
Long vni,
IpPrefix destVmIp,
DeviceId dstDeviceId,
- NetworkType networkType,
+ Type networkType,
boolean install) {
TrafficSelector selector = DefaultTrafficSelector.builder()
@@ -813,7 +822,7 @@
.matchIPDst(destVmIp)
.build();
- PortNumber portNum = tunnelPortNumByNetType(networkType.name(),
+ PortNumber portNum = tunnelPortNumByNetType(networkType,
osNodeService.node(deviceId));
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
@@ -841,7 +850,7 @@
String segmentId,
Subnet updatedSubnet,
Set<Subnet> routableSubnets,
- NetworkType networkType,
+ Type networkType,
boolean install) {
//At first we install flow rules to gateway with segId and gatewayIp of updated subnet
setRulesToGatewayWithDstIp(osNode, sourceNatGateway, segmentId,
@@ -863,7 +872,7 @@
OpenstackNode sourceNatGateway,
String segmentId,
IpAddress dstIp,
- NetworkType networkType,
+ Type networkType,
boolean install) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
@@ -876,7 +885,7 @@
case GRE:
sBuilder.matchTunnelId(Long.parseLong(segmentId));
- PortNumber portNum = tunnelPortNumByNetType(networkType.name(), osNode);
+ PortNumber portNum = tunnelPortNumByNetType(networkType, osNode);
tBuilder.extension(buildExtension(
deviceService,
@@ -975,7 +984,7 @@
private void setRulesToController(DeviceId deviceId,
String segmentId,
IpPrefix srcSubnet,
- NetworkType networkType,
+ Type networkType,
boolean install) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
@@ -999,7 +1008,7 @@
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
- if (networkType.equals(NetworkType.VLAN)) {
+ if (networkType == VLAN) {
tBuilder.popVlan();
}
@@ -1016,7 +1025,7 @@
}
private void setRouterAdminRules(String segmentId,
- NetworkType networkType,
+ Type networkType,
boolean install) {
TrafficTreatment treatment;
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
@@ -1288,7 +1297,9 @@
private void instPortDetected(InstancePort instPort) {
Network network = osNetworkAdminService.network(instPort.networkId());
- if (network.getNetworkType() == FLAT) {
+ Type netType = osNetworkAdminService.networkType(instPort.networkId());
+
+ if (netType == FLAT) {
return;
}
@@ -1298,13 +1309,15 @@
gwNode.intgBridge(),
Long.parseLong(network.getProviderSegID()),
IpPrefix.valueOf(instPort.ipAddress(), VM_PREFIX),
- instPort.deviceId(), network.getNetworkType(), true));
+ instPort.deviceId(), netType, true));
}
}
private void instPortRemoved(InstancePort instPort) {
Network network = osNetworkAdminService.network(instPort.networkId());
- if (network.getNetworkType() == FLAT) {
+ Type netType = osNetworkAdminService.networkType(instPort.networkId());
+
+ if (netType == FLAT) {
return;
}
@@ -1314,7 +1327,7 @@
gwNode.intgBridge(),
Long.parseLong(network.getProviderSegID()),
IpPrefix.valueOf(instPort.ipAddress(), VM_PREFIX),
- instPort.deviceId(), network.getNetworkType(), false));
+ instPort.deviceId(), netType, false));
}
}
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingIcmpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingIcmpHandler.java
index 41c973e..977fe36 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingIcmpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingIcmpHandler.java
@@ -102,10 +102,6 @@
private static final String ERR_REQ = "Failed to handle ICMP request: ";
private static final String ERR_DUPLICATE = " already exists";
- private static final String VXLAN = "VXLAN";
- private static final String GRE = "GRE";
- private static final String VLAN = "VLAN";
-
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected CoreService coreService;
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
index 1f0f874..d1072cb 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
@@ -42,6 +42,7 @@
import org.onosproject.openstacknetworking.api.InstancePort;
import org.onosproject.openstacknetworking.api.InstancePortService;
import org.onosproject.openstacknetworking.api.OpenstackFlowRuleService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
import org.onosproject.openstacknetworking.api.OpenstackRouterService;
import org.onosproject.openstacknetworking.util.RulePopulatorUtil;
@@ -54,7 +55,6 @@
import org.onosproject.store.service.StorageService;
import org.openstack4j.model.network.IP;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Subnet;
import org.osgi.service.component.annotations.Activate;
@@ -229,6 +229,8 @@
TpPort patPort, IpAddress externalIp,
ExternalPeerRouter externalPeerRouter) {
Network osNet = osNetworkService.network(srcInstPort.networkId());
+ Type netType = osNetworkService.networkType(srcInstPort.networkId());
+
if (osNet == null) {
final String error = String.format("%s network %s not found",
ERR_PACKETIN, srcInstPort.networkId());
@@ -237,14 +239,14 @@
setDownstreamRules(srcInstPort,
osNet.getProviderSegID(),
- osNet.getNetworkType(),
+ netType,
externalIp,
externalPeerRouter,
patPort,
packetIn);
setUpstreamRules(osNet.getProviderSegID(),
- osNet.getNetworkType(),
+ netType,
externalIp,
externalPeerRouter,
patPort,
@@ -252,7 +254,7 @@
}
private void setDownstreamRules(InstancePort srcInstPort, String segmentId,
- NetworkType networkType,
+ Type networkType,
IpAddress externalIp,
ExternalPeerRouter externalPeerRouter,
TpPort patPort,
@@ -323,7 +325,7 @@
});
}
- private TrafficTreatment getDownStreamTreatment(NetworkType networkType,
+ private TrafficTreatment getDownStreamTreatment(Type networkType,
TrafficTreatment.Builder tBuilder,
OpenstackNode gNode,
OpenstackNode srcNode) {
@@ -332,7 +334,7 @@
switch (networkType) {
case VXLAN:
case GRE:
- PortNumber portNum = tunnelPortNumByNetType(networkType.name(), gNode);
+ PortNumber portNum = tunnelPortNumByNetType(networkType, gNode);
tmpBuilder.extension(RulePopulatorUtil.buildExtension(
deviceService,
gNode.intgBridge(),
@@ -352,7 +354,7 @@
}
private void setUpstreamRules(String segmentId,
- NetworkType networkType,
+ Type networkType,
IpAddress externalIp,
ExternalPeerRouter externalPeerRouter,
TpPort patPort,
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java
index d162920..15920fe 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSecurityGroupHandler.java
@@ -48,6 +48,7 @@
import org.onosproject.openstacknetworking.api.InstancePortEvent;
import org.onosproject.openstacknetworking.api.InstancePortListener;
import org.onosproject.openstacknetworking.api.OpenstackFlowRuleService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkEvent;
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
@@ -63,7 +64,6 @@
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.SecurityGroup;
import org.openstack4j.model.network.SecurityGroupRule;
@@ -107,6 +107,9 @@
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_CT_DROP_RULE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_CT_HOOK_RULE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_CT_RULE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN;
import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_PORT_PRE_REMOVE;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_SECURITY_GROUP;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_SECURITY_GROUP_DEFAULT;
@@ -217,10 +220,6 @@
private static final String INGRESS = "INGRESS";
private static final IpPrefix IP_PREFIX_ANY = Ip4Prefix.valueOf("0.0.0.0/0");
- private static final String VXLAN = "VXLAN";
- private static final String GRE = "GRE";
- private static final String VLAN = "VLAN";
-
// We expose pipeline structure to SONA application considering removing pipeline soon.
private static final int GOTO_CONNTRACK_TABLE = CT_TABLE;
private static final int GOTO_JUMP_TABLE = JUMP_TABLE;
@@ -582,11 +581,11 @@
private void buildTunnelId(TrafficSelector.Builder sBuilder, String netId) {
String segId = osNetService.segmentId(netId);
- String netType = osNetService.networkType(netId);
+ Type netType = osNetService.networkType(netId);
- if (VLAN.equals(netType)) {
+ if (netType == VLAN) {
sBuilder.matchVlanId(VlanId.vlanId(segId));
- } else if (VXLAN.equals(netType) || GRE.equals(netType)) {
+ } else if (netType == VXLAN || netType == GRE) {
sBuilder.matchTunnelId(Long.valueOf(segId));
} else {
log.warn("Cannot tag the VID due to lack of support of virtual network type {}", netType);
@@ -907,7 +906,7 @@
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
Network net = osNetService.network(instPort.networkId());
- NetworkType netType = net.getNetworkType();
+ Type netType = osNetService.networkType(instPort.networkId());
String segId = net.getProviderSegID();
switch (netType) {
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java
index 3670390..3ac0c0d 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java
@@ -46,6 +46,7 @@
import org.onosproject.openstacknetworking.api.InstancePortListener;
import org.onosproject.openstacknetworking.api.InstancePortService;
import org.onosproject.openstacknetworking.api.OpenstackFlowRuleService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkEvent;
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
@@ -54,7 +55,6 @@
import org.onosproject.openstacknode.api.OpenstackNodeListener;
import org.onosproject.openstacknode.api.OpenstackNodeService;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Subnet;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
@@ -85,6 +85,10 @@
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REPLY_RULE;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REQUEST_RULE;
import static org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE_DEFAULT;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC;
@@ -299,6 +303,8 @@
if (ARP_BROADCAST_MODE.equals(getArpMode())) {
+ Type netType = osNetworkService.networkType(network.getId());
+
String gateway = osSubnet.getGateway();
if (gateway == null) {
return;
@@ -307,11 +313,10 @@
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
- if (NetworkType.VLAN == network.getNetworkType()) {
+ if (netType == VLAN) {
sBuilder.matchVlanId(VlanId.vlanId(network.getProviderSegID()));
tBuilder.popVlan();
- } else if (NetworkType.VXLAN == network.getNetworkType() ||
- NetworkType.GRE == network.getNetworkType()) {
+ } else if (netType == VXLAN || netType == GRE) {
// do not remove fake gateway ARP rules, if there is another gateway
// which has the same subnet that to be removed
// this only occurs if we have duplicated subnets associated with
@@ -371,9 +376,9 @@
* @param install installation flag
*/
private void setArpRequestRule(InstancePort port, boolean install) {
- NetworkType type = osNetworkService.network(port.networkId()).getNetworkType();
+ Type netType = osNetworkService.networkType(port.networkId());
- switch (type) {
+ switch (netType) {
case VXLAN:
case GRE:
setRemoteArpRequestRuleForTunnel(port, install);
@@ -393,9 +398,9 @@
* @param install installation flag
*/
private void setArpReplyRule(InstancePort port, boolean install) {
- NetworkType type = osNetworkService.network(port.networkId()).getNetworkType();
+ Type netType = osNetworkService.networkType(port.networkId());
- switch (type) {
+ switch (netType) {
case VXLAN:
setArpReplyRuleForVxlan(port, install);
break;
@@ -510,26 +515,26 @@
// a helper method
private TrafficSelector getArpReplySelectorForVxlan(InstancePort port) {
- return getArpReplySelectorForVnet(port, NetworkType.VXLAN);
+ return getArpReplySelectorForVnet(port, VXLAN);
}
// a helper method
private TrafficSelector getArpReplySelectorForGre(InstancePort port) {
- return getArpReplySelectorForVnet(port, NetworkType.GRE);
+ return getArpReplySelectorForVnet(port, GRE);
}
// a helper method
private TrafficSelector getArpReplySelectorForVlan(InstancePort port) {
- return getArpReplySelectorForVnet(port, NetworkType.VLAN);
+ return getArpReplySelectorForVnet(port, VLAN);
}
// a helper method
private TrafficSelector getArpReplySelectorForVnet(InstancePort port,
- NetworkType type) {
+ Type type) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
- if (type == NetworkType.VLAN) {
+ if (type == VLAN) {
String segId = osNetworkService.network(port.networkId()).getProviderSegID();
sBuilder.matchVlanId(VlanId.vlanId(segId));
}
@@ -546,31 +551,31 @@
private void setLocalArpReplyTreatmentForVxlan(TrafficSelector selector,
InstancePort port,
boolean install) {
- setLocalArpReplyTreatmentForVnet(selector, port, NetworkType.VXLAN, install);
+ setLocalArpReplyTreatmentForVnet(selector, port, VXLAN, install);
}
// a helper method
private void setLocalArpReplyTreatmentForGre(TrafficSelector selector,
InstancePort port,
boolean install) {
- setLocalArpReplyTreatmentForVnet(selector, port, NetworkType.GRE, install);
+ setLocalArpReplyTreatmentForVnet(selector, port, GRE, install);
}
// a helper method
private void setLocalArpReplyTreatmentForVlan(TrafficSelector selector,
InstancePort port,
boolean install) {
- setLocalArpReplyTreatmentForVnet(selector, port, NetworkType.VLAN, install);
+ setLocalArpReplyTreatmentForVnet(selector, port, VLAN, install);
}
// a helper method
private void setLocalArpReplyTreatmentForVnet(TrafficSelector selector,
InstancePort port,
- NetworkType type,
+ Type type,
boolean install) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
- if (type == NetworkType.VLAN) {
+ if (type == VLAN) {
tBuilder.popVlan();
}
@@ -739,7 +744,7 @@
log.warn("Network is not specified.");
return false;
} else {
- return network.getNetworkType() != NetworkType.FLAT;
+ return network.getProviderSegID() != null;
}
}
@@ -865,8 +870,7 @@
// delegated to switch to handle
osNetworkService.subnets().stream().filter(subnet ->
osNetworkService.network(subnet.getNetworkId()) != null &&
- osNetworkService.network(subnet.getNetworkId())
- .getNetworkType() != NetworkType.FLAT)
+ osNetworkService.networkType(subnet.getNetworkId()) != FLAT)
.forEach(subnet -> {
String netId = subnet.getNetworkId();
Network net = osNetworkService.network(netId);
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
index 7988375..e4b22b5 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
@@ -39,13 +39,13 @@
import org.onosproject.openstacknetworking.api.InstancePortListener;
import org.onosproject.openstacknetworking.api.InstancePortService;
import org.onosproject.openstacknetworking.api.OpenstackFlowRuleService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkEvent;
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
import org.onosproject.openstacknode.api.OpenstackNode;
import org.onosproject.openstacknode.api.OpenstackNodeService;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Port;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@@ -492,7 +492,7 @@
private void setNetworkBlockRules(Network network, boolean install) {
- NetworkType type = network.getNetworkType();
+ Type type = osNetworkService.networkType(network.getId());
// TODO: we block a network traffic by referring to segment ID for now
// we might need to find a better way to block the traffic of a network
@@ -740,8 +740,7 @@
* @param install install flag, add the rule if true, remove it otherwise
*/
private void setNetworkRules(InstancePort instPort, boolean install) {
- Network network = osNetworkService.network(instPort.networkId());
- NetworkType type = network.getNetworkType();
+ Type type = osNetworkService.networkType(instPort.networkId());
switch (type) {
case VXLAN:
@@ -790,8 +789,7 @@
* @param instPort instance port
*/
private void removeVportRules(InstancePort instPort) {
- Network network = osNetworkService.network(instPort.networkId());
- NetworkType type = network.getNetworkType();
+ Type type = osNetworkService.networkType(instPort.networkId());
switch (type) {
case VXLAN:
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHostProvider.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHostProvider.java
index 828e647..1b42ccf 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHostProvider.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHostProvider.java
@@ -41,13 +41,13 @@
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.openstacknetworking.api.Constants;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
import org.onosproject.openstacknode.api.OpenstackNode;
import org.onosproject.openstacknode.api.OpenstackNodeEvent;
import org.onosproject.openstacknode.api.OpenstackNodeListener;
import org.onosproject.openstacknode.api.OpenstackNodeService;
import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
@@ -72,6 +72,7 @@
import static org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_VM;
import static org.onosproject.openstacknetworking.api.Constants.PORT_NAME_VHOST_USER_PREFIX_VM;
import static org.onosproject.openstacknetworking.api.Constants.portNamePrefixMap;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER;
@@ -230,7 +231,8 @@
.set(ANNOTATION_CREATE_TIME, String.valueOf(createTime));
// FLAT typed network does not require segment ID
- if (osNet.getNetworkType() != NetworkType.FLAT) {
+ Type netType = osNetworkService.networkType(osNet.getId());
+ if (netType != FLAT) {
annotations.set(ANNOTATION_SEGMENT_ID, osNet.getProviderSegID());
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
index 66d1f2a..c4e3803 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
@@ -59,6 +59,7 @@
import org.onosproject.openstacknetworking.api.Constants.VnicType;
import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
import org.onosproject.openstacknetworking.api.InstancePort;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
import org.onosproject.openstacknetworking.api.OpenstackRouterAdminService;
import org.onosproject.openstacknetworking.api.OpenstackRouterService;
@@ -769,9 +770,9 @@
.append(COMMA);
String modifiedDstIp = dstIp;
- if (osNetService.networkType(srcInstancePort.networkId()).equals(VXLAN) ||
- osNetService.networkType(srcInstancePort.networkId()).equals(GRE) ||
- osNetService.networkType(srcInstancePort.networkId()).equals(VLAN)) {
+ if (osNetService.networkType(srcInstancePort.networkId()) == Type.VXLAN ||
+ osNetService.networkType(srcInstancePort.networkId()) == Type.GRE ||
+ osNetService.networkType(srcInstancePort.networkId()) == Type.VLAN) {
if (srcIp.equals(dstIp)) {
modifiedDstIp = osNetService.gatewayIp(srcInstancePort.portId());
requestStringBuilder.append(DL_DST)
@@ -797,9 +798,9 @@
.append(dstIp)
.append(COMMA);
- if (osNetService.networkType(srcInstancePort.networkId()).equals(VXLAN) ||
- osNetService.networkType(srcInstancePort.networkId()).equals(GRE) ||
- osNetService.networkType(srcInstancePort.networkId()).equals(VLAN)) {
+ if (osNetService.networkType(srcInstancePort.networkId()) == Type.VXLAN ||
+ osNetService.networkType(srcInstancePort.networkId()) == Type.GRE ||
+ osNetService.networkType(srcInstancePort.networkId()) == Type.VLAN) {
requestStringBuilder.append(TUN_ID)
.append(osNetService.segmentId(srcInstancePort.networkId()))
.append(COMMA);
@@ -1060,7 +1061,7 @@
public static PortNumber tunnelPortNumByNetId(String netId,
OpenstackNetworkService netService,
OpenstackNode osNode) {
- String netType = netService.networkType(netId);
+ Type netType = netService.networkType(netId);
if (netType == null) {
return null;
@@ -1076,7 +1077,7 @@
* @param osNode openstack node
* @return tunnel port number
*/
- public static PortNumber tunnelPortNumByNetType(String netType, OpenstackNode osNode) {
+ public static PortNumber tunnelPortNumByNetType(Type netType, OpenstackNode osNode) {
switch (netType) {
case VXLAN:
return osNode.vxlanTunnelPortNum();
diff --git a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkServiceAdapter.java b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkServiceAdapter.java
index b2a3824..88762c6 100644
--- a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkServiceAdapter.java
+++ b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkServiceAdapter.java
@@ -20,6 +20,7 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork.Type;
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
import org.openstack4j.model.network.ExternalGateway;
@@ -109,7 +110,7 @@
}
@Override
- public String networkType(String netId) {
+ public Type networkType(String netId) {
return null;
}
diff --git a/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/OpenstackNetworkingUiMessageHandler.java b/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/OpenstackNetworkingUiMessageHandler.java
index 3b869b6..3c96590 100644
--- a/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/OpenstackNetworkingUiMessageHandler.java
+++ b/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/OpenstackNetworkingUiMessageHandler.java
@@ -43,6 +43,7 @@
import org.onosproject.net.topology.PathService;
import org.onosproject.openstacknetworking.api.InstancePort;
import org.onosproject.openstacknetworking.api.InstancePortService;
+import org.onosproject.openstacknetworking.api.OpenstackNetwork;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
import org.onosproject.openstacknode.api.OpenstackNode;
import org.onosproject.openstacknode.api.OpenstackNodeService;
@@ -74,6 +75,9 @@
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_GATEWAY_MAC_STR;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
+import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN;
/**
* OpenStack Networking UI message handler.
@@ -103,8 +107,6 @@
private static final String OVS_VERSION_2_7 = "2.7";
private static final String OVS_VERSION_2_6 = "2.6";
- private static final String VXLAN = "VXLAN";
- private static final String VLAN = "VLAN";
private static final String DL_DST = "dl_dst=";
private static final String NW_DST = "nw_dst=";
private static final String DEFAULT_REQUEST_STRING = "sudo ovs-appctl ofproto/trace br-int ip";
@@ -467,7 +469,8 @@
}
- private String sendTraceRequestToNode(String srcIp, String dstIp, OpenstackNode openstackNode, boolean uplink) {
+ private String sendTraceRequestToNode(String srcIp, String dstIp,
+ OpenstackNode openstackNode, boolean uplink) {
Optional<InstancePort> instancePort = instancePortService.instancePorts().stream()
.filter(port -> port.ipAddress().getIp4Address().toString().equals(srcIp)
@@ -502,8 +505,9 @@
.append(srcIp)
.append(COMMA);
- if (osNetService.networkType(srcInstancePort.networkId()).equals(VXLAN) ||
- osNetService.networkType(srcInstancePort.networkId()).equals(VLAN)) {
+ OpenstackNetwork.Type netType = osNetService.networkType(srcInstancePort.networkId());
+
+ if (netType == VXLAN || netType == VLAN || netType == GRE) {
if (srcIp.equals(dstIp)) {
dstIp = osNetService.gatewayIp(srcInstancePort.portId());
requestStringBuilder.append(DL_DST)
diff --git a/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/Constants.java b/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/Constants.java
index 0422c65..e78d0e6 100644
--- a/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/Constants.java
+++ b/apps/openstacknode/api/src/main/java/org/onosproject/openstacknode/api/Constants.java
@@ -38,4 +38,10 @@
public static final String DATA_IP = "dataIp";
public static final String VLAN_INTF_NAME = "vlanPort";
public static final String UPLINK_PORT = "uplinkPort";
+
+ public static final String FLAT = "flat";
+ public static final String VLAN = "vlan";
+ public static final String VXLAN = "vxlan";
+ public static final String GRE = "gre";
+ public static final String GENEVE = "geneve";
}
\ No newline at end of file
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
index c6e9395..1b93499 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
@@ -57,7 +57,6 @@
import org.onosproject.ovsdb.rfc.notation.OvsdbSet;
import org.onosproject.ovsdb.rfc.table.Interface;
import org.openstack4j.api.OSClient;
-import org.openstack4j.model.network.NetworkType;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@@ -80,10 +79,12 @@
import static org.onlab.packet.TpPort.tpPort;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
+import static org.onosproject.openstacknode.api.Constants.GRE;
import static org.onosproject.openstacknode.api.Constants.GRE_TUNNEL;
-import static org.onosproject.openstacknode.api.Constants.VXLAN_TUNNEL;
import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
import static org.onosproject.openstacknode.api.Constants.TUNNEL_BRIDGE;
+import static org.onosproject.openstacknode.api.Constants.VXLAN;
+import static org.onosproject.openstacknode.api.Constants.VXLAN_TUNNEL;
import static org.onosproject.openstacknode.api.DpdkConfig.DatapathType.NETDEV;
import static org.onosproject.openstacknode.api.NodeState.COMPLETE;
import static org.onosproject.openstacknode.api.NodeState.DEVICE_CREATED;
@@ -351,7 +352,7 @@
* @param osNode openstack node
*/
private void createVxlanTunnelInterface(OpenstackNode osNode) {
- createTunnelInterface(osNode, NetworkType.VXLAN, VXLAN_TUNNEL);
+ createTunnelInterface(osNode, VXLAN, VXLAN_TUNNEL);
}
/**
@@ -360,7 +361,7 @@
* @param osNode openstack node
*/
private void createGreTunnelInterface(OpenstackNode osNode) {
- createTunnelInterface(osNode, NetworkType.GRE, GRE_TUNNEL);
+ createTunnelInterface(osNode, GRE, GRE_TUNNEL);
}
/**
@@ -369,7 +370,7 @@
* @param osNode openstack node
*/
private void createTunnelInterface(OpenstackNode osNode,
- NetworkType type, String intfName) {
+ String type, String intfName) {
if (isIntfEnabled(osNode, intfName)) {
return;
}
@@ -392,8 +393,8 @@
* @param type network type
* @return tunnel description
*/
- private TunnelDescription buildTunnelDesc(NetworkType type, String intfName) {
- if (type == NetworkType.VXLAN || type == NetworkType.GRE) {
+ private TunnelDescription buildTunnelDesc(String type, String intfName) {
+ if (VXLAN.equals(type) || GRE.equals(type)) {
TunnelDescription.Builder tdBuilder =
DefaultTunnelDescription.builder()
.deviceId(INTEGRATION_BRIDGE)