Fix: resolve the service not found exception caused by openstack4j
Change-Id: I33a5c7e6b91758a61662a77a1b347fd0239219eb
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 7b192f1..d0bab0f 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
@@ -16,6 +16,7 @@
package org.onosproject.openstacknetworking.api;
import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.event.ListenerService;
import org.openstack4j.model.network.ExternalGateway;
@@ -100,6 +101,14 @@
Set<Port> ports(String networkId);
/**
+ * Obtains a set of fixed IP addresses managed by the given network type.
+ *
+ * @param type network type (FLAT, VXLAN, VLAN, etc.)
+ * @return a set of fixed IP addresses
+ */
+ Set<IpPrefix> getFixedIpsByNetworkType(String type);
+
+ /**
* Returns external router mac with supplied external gateway.
*
* @param externalGateway external gateway information
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 fe5f483..e8747cc 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
@@ -17,6 +17,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -26,6 +27,7 @@
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
@@ -51,9 +53,11 @@
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.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;
@@ -111,6 +115,8 @@
private static final String ERR_DUPLICATE = " already exists";
private static final String PORT_NAME_PREFIX_VM = "tap";
+ private static final int PREFIX_LENGTH = 32;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@@ -356,6 +362,49 @@
}
@Override
+ public Set<IpPrefix> getFixedIpsByNetworkType(String type) {
+ if (type == null) {
+ 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());
+ break;
+ case "VXLAN" :
+ networkIds = networks.stream()
+ .filter(n -> n.getNetworkType() == NetworkType.VXLAN)
+ .map(IdEntity::getId).collect(Collectors.toSet());
+ break;
+ case "VLAN" :
+ networkIds = networks.stream()
+ .filter(n -> n.getNetworkType() == NetworkType.VLAN)
+ .map(IdEntity::getId).collect(Collectors.toSet());
+ break;
+ default:
+ break;
+ }
+
+ Set<IP> ips = Sets.newConcurrentHashSet();
+ for (String networkId : networkIds) {
+ osNetworkStore.ports()
+ .stream()
+ .filter(p -> p.getNetworkId().equals(networkId))
+ .filter(p -> p.getFixedIps() != null)
+ .forEach(p -> ips.addAll(p.getFixedIps()));
+ }
+
+ return ips.stream().map(ip -> IpPrefix.valueOf(
+ IpAddress.valueOf(ip.getIpAddress()), PREFIX_LENGTH))
+ .collect(Collectors.toSet());
+ }
+
+ @Override
public ExternalPeerRouter externalPeerRouter(IpAddress ipAddress) {
if (externalPeerRouterMap.containsKey(ipAddress.toString())) {
return externalPeerRouterMap.get(ipAddress.toString()).value();
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 e824ec4..07290ad 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
@@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableSet;
import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
@@ -78,6 +79,11 @@
}
@Override
+ public Set<IpPrefix> getFixedIpsByNetworkType(String type) {
+ return null;
+ }
+
+ @Override
public MacAddress externalPeerRouterMac(ExternalGateway externalGateway) {
return null;
}
diff --git a/apps/openstacktelemetry/api/BUCK b/apps/openstacktelemetry/api/BUCK
index 40a119b..bd27fb6 100644
--- a/apps/openstacktelemetry/api/BUCK
+++ b/apps/openstacktelemetry/api/BUCK
@@ -1,12 +1,9 @@
-include_defs('//apps/openstacknode/openstack4j.bucklet')
-
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//lib:kafka-clients',
'//lib:jersey-client',
'//lib:javax.ws.rs-api',
'//lib:influxdb-java',
- '//lib:openstack4j-core',
]
TEST_DEPS = [
@@ -18,6 +15,4 @@
osgi_jar_with_tests (
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
-
- import_packages = INCLUDE_PACKAGES + ',' + EXCLUDE_PACKAGES + ',' + ALL_PACKAGES,
)
diff --git a/apps/openstacktelemetry/api/pom.xml b/apps/openstacktelemetry/api/pom.xml
index 4536492..9a9baf3 100644
--- a/apps/openstacktelemetry/api/pom.xml
+++ b/apps/openstacktelemetry/api/pom.xml
@@ -54,37 +54,10 @@
</dependency>
<dependency>
- <groupId>org.pacesys</groupId>
- <artifactId>openstack4j-core</artifactId>
- <version>${openstack4j.version}</version>
- </dependency>
-
- <dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.kafka-clients</artifactId>
<version>${kafka-client.version}</version>
</dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>
- ${project.groupId}.${project.artifactId}
- </Bundle-SymbolicName>
- <Import-Package>
- !org.openstack4j.*,
- *
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
</project>
diff --git a/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java b/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java
index d06d3f2..20a4afa 100644
--- a/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java
+++ b/apps/openstacktelemetry/api/src/main/java/org/onosproject/openstacktelemetry/api/Constants.java
@@ -65,4 +65,7 @@
public static final boolean DEFAULT_DISABLE = false;
public static final boolean DEFAULT_ENABLE = true;
+ public static final String VXLAN = "VXLAN";
+ public static final String VLAN = "VLAN";
+ public static final String FLAT = "FLAT";
}
diff --git a/apps/openstacktelemetry/app/BUCK b/apps/openstacktelemetry/app/BUCK
index 69c2c1e..97bc0f9 100644
--- a/apps/openstacktelemetry/app/BUCK
+++ b/apps/openstacktelemetry/app/BUCK
@@ -1,5 +1,3 @@
-include_defs('//apps/openstacknode/openstack4j.bucklet')
-
GRPC_VER = '1.3.1'
COMPILE_DEPS = [
@@ -20,14 +18,6 @@
'//lib:GRPC_1.3',
'//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
'//lib:grpc-protobuf-lite-' + GRPC_VER,
- '//lib:openstack4j-core',
- '//lib:openstack4j-http-connector',
- '//lib:openstack4j-httpclient',
- '//lib:json-patch',
- '//lib:jackson-coreutils',
- '//lib:btf',
- '//lib:msg-simple',
- '//lib:snakeyaml',
]
TEST_DEPS = [
@@ -46,8 +36,4 @@
api_version = '1.0',
api_description = 'OpenStack Network Telemetry REST API',
api_package = 'org.onosproject.openstacktelemetry.web',
-
- # dependency embedding
- import_packages = INCLUDE_PACKAGES + ',' + EXCLUDE_PACKAGES + ',' + ALL_PACKAGES,
- bundle_classpath = get_openstack4j_deps_path() + get_jackson_deps_path()
)
diff --git a/apps/openstacktelemetry/app/pom.xml b/apps/openstacktelemetry/app/pom.xml
index 4573d45..5b0f8bf 100644
--- a/apps/openstacktelemetry/app/pom.xml
+++ b/apps/openstacktelemetry/app/pom.xml
@@ -58,19 +58,19 @@
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
- <version>3.2.0</version>
+ <version>${protobuf-java.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
- <version>1.3.1</version>
+ <version>${io-grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
- <version>1.3.1</version>
+ <version>${io-grpc.version}</version>
</dependency>
<dependency>
@@ -145,47 +145,6 @@
</dependency>
<dependency>
- <groupId>org.pacesys</groupId>
- <artifactId>openstack4j-core</artifactId>
- <version>${openstack4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.pacesys.openstack4j.connectors</groupId>
- <artifactId>openstack4j-http-connector</artifactId>
- <version>${openstack4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.pacesys.openstack4j.connectors</groupId>
- <artifactId>openstack4j-httpclient</artifactId>
- <version>${openstack4j.version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.fge</groupId>
- <artifactId>json-patch</artifactId>
- <version>${json-patch.version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.fge</groupId>
- <artifactId>jackson-coreutils</artifactId>
- <version>${jackson-coreutils.version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.fge</groupId>
- <artifactId>btf</artifactId>
- <version>${btf.version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.fge</groupId>
- <artifactId>msg-simple</artifactId>
- <version>${msg-simple.version}</version>
- </dependency>
- <dependency>
- <groupId>org.yaml</groupId>
- <artifactId>snakeyaml</artifactId>
- <version>${snakeyaml.version}</version>
- </dependency>
-
- <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<scope>test</scope>
@@ -277,21 +236,8 @@
${project.groupId}.${project.artifactId}
</Bundle-SymbolicName>
<Import-Package>
- !org.apache.http.*,
- !com.fasterxml.jackson.dataformat.*,
- !javax.annotation,
*,org.glassfish.jersey.servlet
</Import-Package>
- <Embed-Dependency>
- openstack4j-core,
- openstack4j-http-connector,
- openstack4j-httpclient,
- json-patch,
- jackson-coreutils,
- btf,
- msg-simple,
- snakeyaml
- </Embed-Dependency>
<Web-ContextPath>${web.context}</Web-ContextPath>
</instructions>
</configuration>
diff --git a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java
index 5453a27..9025224 100644
--- a/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java
+++ b/apps/openstacktelemetry/app/src/main/java/org/onosproject/openstacktelemetry/impl/StatsFlowRuleManager.java
@@ -29,12 +29,12 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
+import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
-import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -51,16 +51,12 @@
import org.onosproject.net.flow.criteria.TcpPortCriterion;
import org.onosproject.net.flow.criteria.UdpPortCriterion;
import org.onosproject.net.host.HostService;
-import org.onosproject.openstacknetworking.api.InstancePort;
-import org.onosproject.openstacknetworking.api.InstancePortService;
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
import org.onosproject.openstacktelemetry.api.FlowInfo;
import org.onosproject.openstacktelemetry.api.OpenstackTelemetryService;
import org.onosproject.openstacktelemetry.api.StatsFlowRule;
import org.onosproject.openstacktelemetry.api.StatsFlowRuleAdminService;
import org.onosproject.openstacktelemetry.api.StatsInfo;
-import org.openstack4j.model.network.Network;
-import org.openstack4j.model.network.NetworkType;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -71,7 +67,6 @@
import java.util.Timer;
import java.util.TimerTask;
-import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.packet.Ethernet.TYPE_IPV4;
import static org.onlab.packet.IPv4.PROTOCOL_TCP;
import static org.onlab.packet.IPv4.PROTOCOL_UDP;
@@ -88,11 +83,11 @@
import static org.onosproject.openstacknetworking.api.Constants.VTAP_FLAT_OUTBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_TABLE;
+import static org.onosproject.openstacktelemetry.api.Constants.FLAT;
import static org.onosproject.openstacktelemetry.api.Constants.OPENSTACK_TELEMETRY_APP_ID;
+import static org.onosproject.openstacktelemetry.api.Constants.VLAN;
+import static org.onosproject.openstacktelemetry.api.Constants.VXLAN;
import static org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getBooleanProperty;
-import static org.openstack4j.model.network.NetworkType.FLAT;
-import static org.openstack4j.model.network.NetworkType.VLAN;
-import static org.openstack4j.model.network.NetworkType.VXLAN;
/**
* Flow rule manager for network statistics of a VM.
@@ -126,7 +121,7 @@
protected HostService hostService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
+ protected ComponentConfigService componentConfigService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
@@ -135,9 +130,6 @@
protected OpenstackNetworkService osNetworkService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected InstancePortService instancePortService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OpenstackTelemetryService telemetryService;
@Property(name = REVERSE_PATH_STATS, boolValue = DEFAULT_REVERSE_PATH_STATS,
@@ -173,6 +165,8 @@
protected void activate() {
appId = coreService.registerApplication(OPENSTACK_TELEMETRY_APP_ID);
+ componentConfigService.registerProperties(getClass());
+
this.start();
log.info("Started");
@@ -180,6 +174,9 @@
@Deactivate
protected void deactivate() {
+
+ componentConfigService.unregisterProperties(getClass(), false);
+
log.info("Stopped");
}
@@ -209,10 +206,6 @@
public void createStatFlowRule(StatsFlowRule statsFlowRule) {
setStatFlowRule(statsFlowRule, true);
-
- log.info("Install stat flow rule for SrcIp:{} DstIp:{}",
- statsFlowRule.srcIpPrefix().toString(),
- statsFlowRule.dstIpPrefix().toString());
}
@Override
@@ -221,10 +214,6 @@
flowRuleService.removeFlowRulesById(appId);
setStatFlowRule(statsFlowRule, false);
-
- log.info("Remove stat flow rule for SrcIp:{} DstIp:{}",
- statsFlowRule.srcIpPrefix().toString(),
- statsFlowRule.dstIpPrefix().toString());
}
private void connectTables(DeviceId deviceId, int fromTable, int toTable,
@@ -459,8 +448,11 @@
* @param install flow rule installation flag
*/
private void setStatFlowRuleBase(StatsFlowRule statsFlowRule, boolean install) {
- DeviceId srcDeviceId = getDeviceId(statsFlowRule.srcIpPrefix().address());
- DeviceId dstDeviceId = getDeviceId(statsFlowRule.dstIpPrefix().address());
+
+ IpPrefix srcIp = statsFlowRule.srcIpPrefix();
+ IpPrefix dstIp = statsFlowRule.dstIpPrefix();
+ DeviceId srcDeviceId = getDeviceId(srcIp.address());
+ DeviceId dstDeviceId = getDeviceId(dstIp.address());
if (srcDeviceId == null && dstDeviceId == null) {
return;
@@ -469,42 +461,47 @@
if (srcDeviceId != null) {
connectTables(srcDeviceId, STAT_INBOUND_TABLE, VTAP_INBOUND_TABLE,
statsFlowRule, METRIC_PRIORITY_SOURCE, install);
- }
- if (dstDeviceId != null && egressStats) {
- NetworkType type = getNetworkType(statsFlowRule.dstIpPrefix());
- if (type == VXLAN || type == VLAN) {
- connectTables(dstDeviceId, STAT_OUTBOUND_TABLE, VTAP_OUTBOUND_TABLE,
- statsFlowRule, METRIC_PRIORITY_TARGET, install);
- } else if (type == FLAT) {
- connectTables(dstDeviceId, STAT_FLAT_OUTBOUND_TABLE, VTAP_FLAT_OUTBOUND_TABLE,
- statsFlowRule, METRIC_PRIORITY_TARGET, install);
+ if (install) {
+ log.info("Install ingress stat flow rule for SrcIp:{} DstIp:{}",
+ srcIp.toString(), dstIp.toString());
+ } else {
+ log.info("Remove ingress stat flow rule for SrcIp:{} DstIp:{}",
+ srcIp.toString(), dstIp.toString());
}
}
- }
- /**
- * Obtains the network type that is used by the VM which has the given IP.
- *
- * @param ipPrefix IP prefix
- * @return network type
- */
- private NetworkType getNetworkType(IpPrefix ipPrefix) {
+ Set<IpPrefix> vxlanIps = osNetworkService.getFixedIpsByNetworkType(VXLAN);
+ Set<IpPrefix> vlanIps = osNetworkService.getFixedIpsByNetworkType(VLAN);
+ Set<IpPrefix> flatIps = osNetworkService.getFixedIpsByNetworkType(FLAT);
- MacAddress mac = checkNotNull(getMacAddress(ipPrefix.address()), MAC_NOT_NULL);
- InstancePort instPort = instancePortService.instancePort(mac);
+ int fromTable, toTable;
- if (instPort == null) {
- return null;
+ if (dstDeviceId != null && egressStats) {
+
+ IpPrefix dstIpPrefix = statsFlowRule.dstIpPrefix();
+
+ if (vxlanIps.contains(dstIpPrefix) || vlanIps.contains(dstIpPrefix)) {
+ fromTable = STAT_OUTBOUND_TABLE;
+ toTable = VTAP_OUTBOUND_TABLE;
+ } else if (flatIps.contains(dstIpPrefix)) {
+ fromTable = STAT_FLAT_OUTBOUND_TABLE;
+ toTable = VTAP_FLAT_OUTBOUND_TABLE;
+ } else {
+ return;
+ }
+
+ connectTables(dstDeviceId, fromTable, toTable,
+ statsFlowRule, METRIC_PRIORITY_TARGET, install);
+
+ if (install) {
+ log.info("Install egress stat flow rule for SrcIp:{} DstIp:{}",
+ srcIp.toString(), dstIp.toString());
+ } else {
+ log.info("Remove egress stat flow rule for SrcIp:{} DstIp:{}",
+ srcIp.toString(), dstIp.toString());
+ }
}
-
- Network network = osNetworkService.network(instPort.networkId());
-
- if (network != null) {
- return network.getNetworkType();
- }
-
- return null;
}
/**
diff --git a/apps/openstacktelemetry/pom.xml b/apps/openstacktelemetry/pom.xml
index f6372ad..0bf8590 100644
--- a/apps/openstacktelemetry/pom.xml
+++ b/apps/openstacktelemetry/pom.xml
@@ -31,14 +31,10 @@
<description>SONA Openstack Telemetry Application</description>
<properties>
- <openstack4j.version>3.1.0</openstack4j.version>
<influxdb-java.version>2.2</influxdb-java.version>
<kafka-client.version>0.8.2.2_1</kafka-client.version>
- <json-patch.version>1.9</json-patch.version>
- <jackson-coreutils.version>1.6</jackson-coreutils.version>
- <btf.version>1.2</btf.version>
- <msg-simple.version>1.1</msg-simple.version>
- <snakeyaml.version>1.15</snakeyaml.version>
+ <protobuf-java.version>3.2.0</protobuf-java.version>
+ <io-grpc.version>1.3.1</io-grpc.version>
</properties>
<modules>