[VOL-2617] Replacing org.opencord.config with org.opencord.sadis
Change-Id: Ia453bba3a45cafa25dd0f03bccc7ccbed70b77e5
diff --git a/pom.xml b/pom.xml
index 5ea3f3a..25abd3c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,7 @@
org.opencord.config,
org.onosproject.mcast
</onos.app.requires>
- <cord.config.version>2.0.0-SNAPSHOT</cord.config.version>
+ <sadis.api.version>5.0.0</sadis.api.version>
</properties>
@@ -85,8 +85,9 @@
<dependency>
<groupId>org.opencord</groupId>
- <artifactId>cord-config</artifactId>
- <version>${cord.config.version}</version>
+ <artifactId>sadis-api</artifactId>
+ <version>${sadis.api.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
diff --git a/src/main/java/org/opencord/igmpproxy/IgmpManager.java b/src/main/java/org/opencord/igmpproxy/IgmpManager.java
index 5baf0ff..0bbfe6d 100644
--- a/src/main/java/org/opencord/igmpproxy/IgmpManager.java
+++ b/src/main/java/org/opencord/igmpproxy/IgmpManager.java
@@ -17,6 +17,10 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import org.onosproject.net.Device;
+import org.opencord.sadis.BaseInformationService;
+import org.opencord.sadis.SadisService;
+import org.opencord.sadis.SubscriberAndDeviceInformation;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
@@ -64,8 +68,6 @@
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
-import org.opencord.cordconfig.access.AccessDeviceConfig;
-import org.opencord.cordconfig.access.AccessDeviceData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -94,8 +96,8 @@
@Component(immediate = true)
public class IgmpManager {
- private static final Class<AccessDeviceConfig> CONFIG_CLASS =
- AccessDeviceConfig.class;
+ private static final String APP_NAME = "org.opencord.igmpproxy";
+
private static final Class<IgmpproxyConfig> IGMPPROXY_CONFIG_CLASS =
IgmpproxyConfig.class;
private static final Class<IgmpproxySsmTranslateConfig> IGMPPROXY_SSM_CONFIG_CLASS =
@@ -105,7 +107,7 @@
public static Map<String, GroupMember> groupMemberMap = Maps.newConcurrentMap();
private static ApplicationId appId;
- private static Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>();
+
private static int unSolicitedTimeout = 3; // unit is 1 sec
private static int keepAliveCount = 3;
private static int lastQueryInterval = 2; //unit is 1 sec
@@ -132,22 +134,34 @@
private static final String DEFAULT_PIMSSM_HOST = "127.0.0.1";
private final ScheduledExecutorService scheduledExecutorService =
Executors.newScheduledThreadPool(1);
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected CoreService coreService;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected PacketService packetService;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected MastershipService mastershipService;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected FlowRuleService flowRuleService;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected DeviceService deviceService;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected FlowObjectiveService flowObjectiveService;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected NetworkConfigRegistry networkConfig;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected MulticastRouteService multicastService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected SadisService sadisService;
+
private IgmpPacketProcessor processor = new IgmpPacketProcessor();
private Logger log = LoggerFactory.getLogger(getClass());
private ApplicationId coreAppId;
@@ -156,7 +170,7 @@
private InternalNetworkConfigListener configListener =
new InternalNetworkConfigListener();
private DeviceListener deviceListener = new InternalDeviceListener();
- private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory = null;
+
private ConfigFactory<ApplicationId, IgmpproxyConfig> igmpproxyConfigFactory =
new ConfigFactory<ApplicationId, IgmpproxyConfig>(
SubjectFactories.APP_SUBJECT_FACTORY, IGMPPROXY_CONFIG_CLASS, "igmpproxy") {
@@ -183,24 +197,17 @@
return unSolicitedTimeout;
}
+ protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
+ private static Map<DeviceId, SubscriberAndDeviceInformation> oltData = new ConcurrentHashMap<>();
+
+
@Activate
protected void activate() {
- appId = coreService.registerApplication("org.opencord.igmpproxy");
+ appId = coreService.registerApplication(APP_NAME);
coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME);
packetService.addProcessor(processor, PacketProcessor.director(4));
IgmpSender.init(packetService, mastershipService);
- if (networkConfig.getConfigFactory(CONFIG_CLASS) == null) {
- configFactory =
- new ConfigFactory<DeviceId, AccessDeviceConfig>(
- SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") {
- @Override
- public AccessDeviceConfig createConfig() {
- return new AccessDeviceConfig();
- }
- };
- networkConfig.registerConfigFactory(configFactory);
- }
networkConfig.registerConfigFactory(igmpproxySsmConfigFactory);
networkConfig.registerConfigFactory(igmpproxyConfigFactory);
networkConfig.addListener(configListener);
@@ -208,18 +215,15 @@
configListener.reconfigureNetwork(networkConfig.getConfig(appId, IGMPPROXY_CONFIG_CLASS));
configListener.reconfigureSsmTable(networkConfig.getConfig(appId, IGMPPROXY_SSM_CONFIG_CLASS));
- networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach(
- subject -> {
- AccessDeviceConfig config = networkConfig.getConfig(subject,
- AccessDeviceConfig.class);
- if (config != null) {
- AccessDeviceData data = config.getAccessDevice();
- oltData.put(data.deviceId(), data);
- }
- }
- );
+ subsService = sadisService.getSubscriberInfoService();
- oltData.keySet().forEach(d -> provisionDefaultFlows(d));
+ networkConfig.getSubjects(DeviceId.class).forEach(subject -> {
+ SubscriberAndDeviceInformation olt = subsService.get(subject.toString());
+ if (olt != null) {
+ oltData.put(subject, olt);
+ }
+ });
+
if (connectPointMode) {
provisionConnectPointFlows();
} else {
@@ -246,9 +250,6 @@
// de-register and null our handler
networkConfig.removeListener(configListener);
- if (configFactory != null) {
- networkConfig.unregisterConfigFactory(configFactory);
- }
networkConfig.unregisterConfigFactory(igmpproxyConfigFactory);
networkConfig.unregisterConfigFactory(igmpproxySsmConfigFactory);
deviceService.removeListener(deviceListener);
@@ -598,7 +599,7 @@
public static PortNumber getDeviceUplink(DeviceId devId) {
if (oltData.get(devId) != null) {
- return oltData.get(devId).uplink();
+ return PortNumber.portNumber(oltData.get(devId).uplinkPort());
} else {
return null;
}
@@ -655,8 +656,7 @@
}
private boolean isUplink(DeviceId device, PortNumber port) {
- return ((!connectPointMode) && oltData.containsKey(device)
- && oltData.get(device).uplink().equals(port));
+ return ((!connectPointMode) && getDeviceUplink(device).equals(port));
}
private class InternalDeviceListener implements DeviceListener {
@@ -795,15 +795,7 @@
switch (event.type()) {
case CONFIG_ADDED:
case CONFIG_UPDATED:
- if (event.configClass().equals(CONFIG_CLASS)) {
- AccessDeviceConfig config =
- networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
- if (config != null) {
- oltData.put(config.getAccessDevice().deviceId(), config.getAccessDevice());
- provisionDefaultFlows((DeviceId) event.subject());
- provisionUplinkFlows((DeviceId) event.subject());
- }
- }
+ // NOTE how to know if something has changed in sadis?
if (event.configClass().equals(IGMPPROXY_CONFIG_CLASS)) {
IgmpproxyConfig config = networkConfig.getConfig(appId, IGMPPROXY_CONFIG_CLASS);
@@ -835,10 +827,7 @@
case CONFIG_UNREGISTERED:
break;
case CONFIG_REMOVED:
- if (event.configClass().equals(CONFIG_CLASS)) {
- oltData.remove(event.subject());
- }
-
+ // NOTE how to know if something has changed in sadis?
default:
break;
}
@@ -847,8 +836,9 @@
private void provisionDefaultFlows(DeviceId deviceId) {
List<Port> ports = deviceService.getPorts(deviceId);
+
ports.stream()
- .filter(p -> (!oltData.get(p.element().id()).uplink().equals(p.number()) && p.isEnabled()))
+ .filter(p -> (!getDeviceUplink(((Device) p.element()).id()).equals(p.number()) && p.isEnabled()))
.forEach(p -> processFilterObjective((DeviceId) p.element().id(), p.number(), false));
}
@@ -857,7 +847,7 @@
return;
}
- processFilterObjective(deviceId, oltData.get(deviceId).uplink(), false);
+ processFilterObjective(deviceId, getDeviceUplink(deviceId), false);
}
private void provisionUplinkFlows() {
@@ -869,7 +859,7 @@
}
private void unprovisionUplinkFlows() {
oltData.keySet().forEach(deviceId ->
- processFilterObjective(deviceId, oltData.get(deviceId).uplink(), true));
+ processFilterObjective(deviceId, getDeviceUplink(deviceId), true));
}
private void provisionConnectPointFlows() {
diff --git a/src/test/java/org/opencord/igmpproxy/IgmpManagerBase.java b/src/test/java/org/opencord/igmpproxy/IgmpManagerBase.java
index fa4e504..82d342c 100644
--- a/src/test/java/org/opencord/igmpproxy/IgmpManagerBase.java
+++ b/src/test/java/org/opencord/igmpproxy/IgmpManagerBase.java
@@ -15,28 +15,17 @@
*/
package org.opencord.igmpproxy;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
+import com.google.common.collect.ImmutableSet;
import org.onlab.packet.Ethernet;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
-import org.onlab.packet.VlanId;
+import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.mcast.api.McastListener;
import org.onosproject.mcast.api.McastRoute;
import org.onosproject.mcast.api.McastRouteData;
import org.onosproject.mcast.api.MulticastRouteService;
-import org.onosproject.net.config.ConfigFactory;
-import org.onosproject.net.config.NetworkConfigRegistryAdapter;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
@@ -49,6 +38,8 @@
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.config.Config;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigRegistryAdapter;
import org.onosproject.net.config.basics.McastConfig;
import org.onosproject.net.config.basics.SubjectFactories;
import org.onosproject.net.device.DeviceServiceAdapter;
@@ -59,13 +50,18 @@
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketServiceAdapter;
-import org.opencord.cordconfig.access.AccessDeviceConfig;
-import org.opencord.cordconfig.access.AccessDeviceData;
+import org.opencord.sadis.BandwidthProfileInformation;
+import org.opencord.sadis.BaseInformationService;
+import org.opencord.sadis.SadisService;
+import org.opencord.sadis.SubscriberAndDeviceInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
public class IgmpManagerBase {
@@ -90,8 +86,10 @@
protected static final ConnectPoint CONNECT_POINT_A = new ConnectPoint(DEVICE_ID_OF_A, PORT_A);
protected static final ConnectPoint CONNECT_POINT_B = new ConnectPoint(DEVICE_ID_OF_B, PORT_B);
- // setOfDevices which will store device id of two olts
- protected Set<DeviceId> setOfDevices = new HashSet<DeviceId>(Arrays.asList(DEVICE_ID_OF_A, DEVICE_ID_OF_B));
+ protected static final String CLIENT_NAS_PORT_ID = "PON 1/1";
+ protected static final String CLIENT_CIRCUIT_ID = "CIR-PON 1/1";
+ protected String dsBpId = "HSIA-DS";
+
protected List<Port> lsPorts = new ArrayList<Port>();
// Flag for adding two different devices in oltData
protected boolean flagForDevice = true;
@@ -130,7 +128,6 @@
}
}
- static final Class<AccessDeviceConfig> CONFIG_CLASS = AccessDeviceConfig.class;
static final Class<IgmpproxyConfig> IGMPPROXY_CONFIG_CLASS = IgmpproxyConfig.class;
static final Class<IgmpproxySsmTranslateConfig> IGMPPROXY_SSM_CONFIG_CLASS = IgmpproxySsmTranslateConfig.class;
static final Class<McastConfig> MCAST_CONFIG_CLASS = McastConfig.class;
@@ -177,48 +174,6 @@
}
- static class MockAccessDeviceConfig extends AccessDeviceConfig {
-
- public MockAccessDeviceConfig() {
- super();
- }
-
- public MockAccessDeviceConfig(DeviceId id) {
- super();
- subject = id;
- }
-
- @Override
- public AccessDeviceData getAccessDevice() {
- PortNumber uplink = PortNumber.portNumber(3);
- VlanId vlan = VlanId.vlanId((short) 0);
- ObjectMapper mapper = new ObjectMapper();
- JsonNode defaultVlanNode = null;
- try {
- defaultVlanNode = (JsonNode) mapper.readTree("{\"driver\":\"pmc-olt\" , \"type \" : \"OLT\"}");
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- Optional<VlanId> defaultVlan;
- if (defaultVlanNode.isMissingNode()) {
- defaultVlan = Optional.empty();
- } else {
- defaultVlan = Optional.of(VlanId.vlanId(defaultVlanNode.shortValue()));
- }
- return new AccessDeviceData(subject, uplink, vlan, defaultVlan);
- }
- }
-
- ConfigFactory<DeviceId, AccessDeviceConfig> cf =
- new ConfigFactory<DeviceId, AccessDeviceConfig>(
- SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") {
- @Override
- public AccessDeviceConfig createConfig() {
- return new MockAccessDeviceConfig();
- }
- };
-
class TestNetworkConfigRegistry extends NetworkConfigRegistryAdapter {
Boolean igmpOnPodFlag = false;
TestNetworkConfigRegistry(Boolean igmpFlag) {
@@ -226,36 +181,24 @@
}
@SuppressWarnings("unchecked")
@Override
- public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
- if (configClass.getName().equalsIgnoreCase("org.opencord.igmpproxy.IgmpproxyConfig")) {
- IgmpproxyConfig igmpproxyConfig = new MockIgmpProxyConfig(igmpOnPodFlag);
- return (C) igmpproxyConfig;
- } else if (configClass.getName().equalsIgnoreCase("org.opencord.cordconfig.access.AccessDeviceConfig")) {
-
- if (subject.toString().equals(DEVICE_ID_OF_A.toString())) {
- AccessDeviceConfig accessDeviceConfig = new MockAccessDeviceConfig(DEVICE_ID_OF_A);
- return (C) accessDeviceConfig;
- } else {
- AccessDeviceConfig accessDeviceConfig = new MockAccessDeviceConfig(DEVICE_ID_OF_B);
- return (C) accessDeviceConfig;
- }
- } else {
- super.getConfig(subject, configClass);
+ public <S> Set<S> getSubjects(Class<S> subjectClass) {
+ if (subjectClass.getName().equalsIgnoreCase("org.onosproject.net.DeviceId")) {
+ return (Set<S>) ImmutableSet.of(DEVICE_ID_OF_A, DEVICE_ID_OF_B);
}
return null;
}
- @SuppressWarnings("unchecked")
- @Override
- public <S, C extends Config<S>> ConfigFactory<S, C> getConfigFactory(Class<C> configClass) {
- return (ConfigFactory<S, C>) cf;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass) {
- return (Set<S>) setOfDevices;
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
+ if (configClass.getName().equalsIgnoreCase("org.opencord.igmpproxy.IgmpproxyConfig")) {
+ IgmpproxyConfig igmpproxyConfig = new MockIgmpProxyConfig(igmpOnPodFlag);
+ return (C) igmpproxyConfig;
+ } else {
+ super.getConfig(subject, configClass);
+ }
+ return null;
+ }
}
@@ -443,4 +386,86 @@
}
}
+ protected class MockSadisService implements SadisService {
+
+ @Override
+ public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() {
+ return new MockSubService();
+ }
+
+ @Override
+ public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() {
+ return new MockBpService();
+ }
+ }
+
+ private class MockBpService implements BaseInformationService<BandwidthProfileInformation> {
+
+ @Override
+ public void invalidateAll() {
+
+ }
+
+ @Override
+ public void invalidateId(String id) {
+
+ }
+
+ @Override
+ public BandwidthProfileInformation get(String id) {
+ if (id.equals(dsBpId)) {
+ BandwidthProfileInformation bpInfo = new BandwidthProfileInformation();
+ bpInfo.setAssuredInformationRate(0);
+ bpInfo.setCommittedInformationRate(10000);
+ bpInfo.setCommittedBurstSize(1000L);
+ bpInfo.setExceededBurstSize(2000L);
+ bpInfo.setExceededInformationRate(20000);
+ return bpInfo;
+ }
+ return null;
+ }
+
+ @Override
+ public BandwidthProfileInformation getfromCache(String id) {
+ return null;
+ }
+ }
+
+ private class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> {
+ MockSubscriberAndDeviceInformation sub =
+ new MockSubscriberAndDeviceInformation(CLIENT_NAS_PORT_ID,
+ CLIENT_NAS_PORT_ID, CLIENT_CIRCUIT_ID, null, null);
+
+ @Override
+ public SubscriberAndDeviceInformation get(String id) {
+ return sub;
+ }
+
+ @Override
+ public void invalidateAll() {
+ }
+
+ @Override
+ public void invalidateId(String id) {
+ }
+
+ @Override
+ public SubscriberAndDeviceInformation getfromCache(String id) {
+ return null;
+ }
+ }
+
+ private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation {
+
+ MockSubscriberAndDeviceInformation(String id, String nasPortId,
+ String circuitId, MacAddress hardId,
+ Ip4Address ipAddress) {
+ this.setHardwareIdentifier(hardId);
+ this.setId(id);
+ this.setIPAddress(ipAddress);
+ this.setNasPortId(nasPortId);
+ this.setCircuitId(circuitId);
+ }
+ }
+
}
diff --git a/src/test/java/org/opencord/igmpproxy/IgmpManagerTest.java b/src/test/java/org/opencord/igmpproxy/IgmpManagerTest.java
index 62ab4c0..21a83fe 100644
--- a/src/test/java/org/opencord/igmpproxy/IgmpManagerTest.java
+++ b/src/test/java/org/opencord/igmpproxy/IgmpManagerTest.java
@@ -42,6 +42,7 @@
igmpManager.packetService = new MockPacketService();
igmpManager.flowRuleService = new FlowRuleServiceAdapter();
igmpManager.multicastService = new TestMulticastRouteService();
+ igmpManager.sadisService = new MockSadisService();
// By default - we send query messages
SingleStateMachine.sendQuery = true;
}
@@ -127,5 +128,4 @@
}
assertEquals(1, savedPackets.size());
}
-
}