made protocols static; TODO add device ID and configuration support
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java
index a5a456f..98aa2ad 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java
@@ -24,6 +24,8 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
+import org.onosproject.fpcagent.protocols.DpnNgicCommunicator;
+import org.onosproject.fpcagent.protocols.DpnP4Communicator;
import org.onosproject.fpcagent.providers.DpnDeviceListener;
import org.onosproject.fpcagent.providers.DpnProviderService;
import org.onosproject.fpcagent.util.ConfigHelper;
@@ -34,6 +36,7 @@
import org.onosproject.fpcagent.workers.ZMQSBSubscriberManager;
import org.onosproject.net.config.*;
import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.restconf.api.RestconfService;
import org.onosproject.yang.model.ModelConverter;
import org.onosproject.yang.model.RpcRegistry;
@@ -89,6 +92,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private RestconfService restconfService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private FlowRuleService flowRuleService;
+
/* Variables */
private IdGenerator notificationIds;
private FpcConfig fpcConfig;
@@ -107,7 +113,7 @@
@Activate
protected void activate() {
- coreService.registerApplication(FPC_APP_ID);
+ ApplicationId applicationId = coreService.registerApplication(FPC_APP_ID);
configService.addListener(configListener);
registry.registerConfigFactory(fpcConfigConfigFactory);
dynamicConfigService.addListener(dynListener);
@@ -117,6 +123,8 @@
JettyServer.createInstance().open();
ParseStream.createInstance().open();
NBEventWorkerManager.createInstance(20, restconfService).open();
+ DpnNgicCommunicator.createInstance();
+ DpnP4Communicator.createInstance(applicationId, flowRuleService);
log.info("FPC Service Started");
}
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java
index cef7592..13062d9 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java
@@ -223,9 +223,9 @@
Class<? extends FpcDpnControlProtocol> controlProtocol = optionalDpn.get().controlProtocol();
// Check if the DPN supports NGIC or P4 protocol
if (controlProtocol.isAssignableFrom(ZmqDpnControlProtocol.class)) {
- dpnCommunicationService = new DpnNgicCommunicator();
+ dpnCommunicationService = DpnNgicCommunicator.getInstance();
} else if (controlProtocol.isAssignableFrom(P4DpnControlProtocol.class)) {
- dpnCommunicationService = new DpnP4Communicator();
+ dpnCommunicationService = DpnP4Communicator.getInstance();
} else {
throw new RuntimeException("Control Protocol is not supported.");
}
@@ -387,9 +387,9 @@
Class<? extends FpcDpnControlProtocol> controlProtocol = optionalDpn.get().controlProtocol();
// Check if the DPN supports NGIC or P4 protocol
if (controlProtocol.isAssignableFrom(ZmqDpnControlProtocol.class)) {
- dpnCommunicationService = new DpnNgicCommunicator();
+ dpnCommunicationService = DpnNgicCommunicator.getInstance();
} else if (controlProtocol.isAssignableFrom(P4DpnControlProtocol.class)) {
- dpnCommunicationService = new DpnP4Communicator();
+ dpnCommunicationService = DpnP4Communicator.getInstance();
} else {
throw new RuntimeException("Control Protocol is not supported.");
}
@@ -541,9 +541,9 @@
final DpnCommunicationService dpnCommunicationService;
Class<? extends FpcDpnControlProtocol> controlProtocol = optionalDpn.get().controlProtocol();
if (controlProtocol.isAssignableFrom(ZmqDpnControlProtocol.class)) {
- dpnCommunicationService = new DpnNgicCommunicator();
+ dpnCommunicationService = DpnNgicCommunicator.getInstance();
} else if (controlProtocol.isAssignableFrom(P4DpnControlProtocol.class)) {
- dpnCommunicationService = new DpnP4Communicator();
+ dpnCommunicationService = DpnP4Communicator.getInstance();
} else {
throw new RuntimeException("Control Protocol is not supported.");
}
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnNgicCommunicator.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnNgicCommunicator.java
index 0332312..6491882 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnNgicCommunicator.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnNgicCommunicator.java
@@ -43,6 +43,22 @@
public class DpnNgicCommunicator extends ZmqDpnControlProtocol implements DpnCommunicationService {
protected static final Logger log = LoggerFactory.getLogger(DpnNgicCommunicator.class);
+ private static DpnNgicCommunicator _instance;
+
+ private DpnNgicCommunicator() {
+ }
+
+ public static DpnNgicCommunicator createInstance() {
+ if(_instance == null) {
+ _instance = new DpnNgicCommunicator();
+ }
+ return _instance;
+ }
+
+ public static DpnNgicCommunicator getInstance() {
+ return _instance;
+ }
+
/**
* Broadcasts the GOODBYE message to all the DPNs
*/
@@ -210,7 +226,7 @@
.put(toUint32(client_id))
.put(toUint32(op_id.longValue()));
- log.debug("create_session: {}", bb.array());
+ log.info("create_session: {}", bb.array());
ZMQSBPublisherManager.getInstance().send(bb);
}
@@ -249,7 +265,7 @@
.put(toUint32(client_id))
.put(toUint32(op_id.longValue()));
- log.debug("modify_bearer: {}", bb.array());
+ log.info("modify_bearer: {}", bb.array());
ZMQSBPublisherManager.getInstance().send(bb);
}
@@ -279,7 +295,7 @@
.put(toUint32(client_id))
.put(toUint32(op_id.longValue()));
- log.debug("delete_session: {}", bb.array());
+ log.info("delete_session: {}", bb.array());
ZMQSBPublisherManager.getInstance().send(bb);
}
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java
index 7228c6c..6a26e60 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/protocols/DpnP4Communicator.java
@@ -93,20 +93,35 @@
// FIXME: should use a cache with timeout
private static Map<Long, Lock> SESS_LOCKS = Maps.newConcurrentMap();
+ private static DpnP4Communicator _instance;
+
private ApplicationId appId;
private DeviceId deviceId;
private FlowRuleService flowRuleService;
- private boolean initialized = false;
- public void init(ApplicationId appId, DeviceId deviceId, FlowRuleService flowRuleService) {
+ private DpnP4Communicator(ApplicationId appId, FlowRuleService flowRuleService) {
this.appId = checkNotNull(appId);
- this.deviceId = checkNotNull(deviceId);
this.flowRuleService = checkNotNull(flowRuleService);
- this.initialized = true;
+ this.deviceId = null;
+ }
+
+ public static DpnP4Communicator createInstance(ApplicationId appId, FlowRuleService flowRuleService) {
+ if (_instance == null) {
+ _instance = new DpnP4Communicator(appId, flowRuleService);
+ }
+ return _instance;
+ }
+
+ public static DpnP4Communicator getInstance() {
+ return _instance;
+ }
+
+ public void setDeviceId(DeviceId deviceId) {
+ this.deviceId = checkNotNull(deviceId);
}
private boolean isNotInit() {
- if (!this.initialized) {
+ if (deviceId == null) {
log.error("Not initialized. Cannot perform operations.");
return true;
} else {