Separated ARP proxy as an independent component and some renaming
- Renamed CordVtnService to DependencyService
- Renamed CordVtnInstanceManager to InstanceManager and added
InstanceService as an interface of the manager implementation
- Renamed package name impl.service to impl.handler
- Added Constants class
Change-Id: I249708c008d5105957aa1d1a796f0ca32025e75c
diff --git a/src/main/java/org/opencord/cordvtn/impl/handler/OltAgentInstanceHandler.java b/src/main/java/org/opencord/cordvtn/impl/handler/OltAgentInstanceHandler.java
new file mode 100644
index 0000000..853963e
--- /dev/null
+++ b/src/main/java/org/opencord/cordvtn/impl/handler/OltAgentInstanceHandler.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.opencord.cordvtn.impl.handler;
+
+import com.google.common.collect.Maps;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+
+import org.opencord.cordvtn.impl.AbstractInstanceHandler;
+import org.opencord.cordvtn.api.CordVtnConfig;
+import org.opencord.cordvtn.api.Instance;
+import org.opencord.cordvtn.api.InstanceHandler;
+import org.onosproject.net.DeviceId;
+
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.opencord.cordconfig.access.AccessAgentConfig;
+import org.opencord.cordconfig.access.AccessAgentData;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static org.onosproject.xosclient.api.VtnServiceApi.ServiceType.OLT_AGENT;
+
+/**
+ * Provides network connectivity for OLT agent instances.
+ */
+@Component(immediate = true)
+public class OltAgentInstanceHandler extends AbstractInstanceHandler implements InstanceHandler {
+
+ private static final Class<AccessAgentConfig> CONFIG_CLASS = AccessAgentConfig.class;
+ private ConfigFactory<DeviceId, AccessAgentConfig> configFactory =
+ new ConfigFactory<DeviceId, AccessAgentConfig>(
+ SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessAgent") {
+ @Override
+ public AccessAgentConfig createConfig() {
+ return new AccessAgentConfig();
+ }
+ };
+
+ private Map<DeviceId, AccessAgentData> oltAgentData = Maps.newConcurrentMap();
+
+ @Activate
+ protected void activate() {
+ serviceType = Optional.of(OLT_AGENT);
+ configListener = new InternalConfigListener();
+ super.activate();
+
+ configRegistry.registerConfigFactory(configFactory);
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ super.deactivate();
+ }
+
+ @Override
+ public void instanceDetected(Instance instance) {
+ log.info("OLT agent instance detected {}", instance);
+ // TODO implement
+ }
+
+ @Override
+ public void instanceRemoved(Instance instance) {
+ log.info("OLT agent instance removed {}", instance);
+ // TODO implement
+ }
+
+ private void readAccessAgentConfig() {
+
+ Set<DeviceId> deviceSubjects = configRegistry.getSubjects(DeviceId.class, CONFIG_CLASS);
+ deviceSubjects.stream().forEach(subject -> {
+ AccessAgentConfig config = configRegistry.getConfig(subject, CONFIG_CLASS);
+ if (config != null) {
+ oltAgentData.put(subject, config.getAgent());
+ }
+ });
+ }
+
+ private class InternalConfigListener implements NetworkConfigListener {
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+
+ switch (event.type()) {
+ case CONFIG_UPDATED:
+ case CONFIG_ADDED:
+ if (event.configClass().equals(CordVtnConfig.class)) {
+ readConfiguration();
+ } else if (event.configClass().equals(CONFIG_CLASS)) {
+ readAccessAgentConfig();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}