ONOS-5450 Initial implementation of OFAgent
- Refactored OFAgent immutable
- Added OFAgentStore and OFAgentEvent
- Implemented OFAgentManager and OFSwitchManager
- Added unit tests
Change-Id: Ie39ad2db9e6bd6259a062371b3ffe116b8c8cc52
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgent.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgent.java
index b44f48e..0db4489 100644
--- a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgent.java
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgent.java
@@ -15,19 +15,29 @@
*/
package org.onosproject.ofagent.api;
-import io.netty.channel.nio.NioEventLoopGroup;
import org.onosproject.incubator.net.virtual.NetworkId;
-import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ExecutorService;
/**
- * Representation of an OF agent, which brokers virtual devices and external
- * controllers by handling OpenFlow connections and messages between them.
+ * Representation of an OpenFlow agent, which holds the mapping between the virtual
+ * network and the external OpenFlow controllers.
*/
public interface OFAgent {
+ enum State {
+
+ /**
+ * Specifies that the ofagent state is started.
+ */
+ STARTED,
+
+ /**
+ * Specifies that the ofagent state is stopped.
+ */
+ STOPPED
+ }
+
/**
* Returns the identifier of the virtual network that this agent cares for.
*
@@ -43,14 +53,11 @@
Set<OFController> controllers();
/**
- * Starts the OpenFlow agent.
+ * Returns the admin state of the agent.
+ *
+ * @return state
*/
- void start();
-
- /**
- * Stops the OpenFlow agent.
- */
- void stop();
+ State state();
/**
* Builder of OF agent entities.
@@ -73,15 +80,6 @@
Builder networkId(NetworkId networkId);
/**
- * Returns OF agent builder with the supplied network services for the
- * virtual network.
- *
- * @param services network services for the virtual network
- * @return of agent builder
- */
- Builder services(Map<Class<?>, Object> services);
-
- /**
* Returns OF agent builder with the supplied controllers.
*
* @param controllers set of openflow controllers
@@ -90,19 +88,11 @@
Builder controllers(Set<OFController> controllers);
/**
- * Returns OF agent builder with the supplied event executor.
+ * Returns OF agent builder with the supplied state.
*
- * @param eventExecutor event executor
+ * @param state state of the agent
* @return of agent builder
*/
- Builder eventExecutor(ExecutorService eventExecutor);
-
- /**
- * Returns OF agent builder with the supplied IO work group.
- *
- * @param ioWorker io worker group
- * @return of agent builder
- */
- Builder ioWorker(NioEventLoopGroup ioWorker);
+ Builder state(State state);
}
}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentAdminService.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentAdminService.java
new file mode 100644
index 0000000..0c6667a
--- /dev/null
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentAdminService.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017-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.onosproject.ofagent.api;
+
+import org.onosproject.incubator.net.virtual.NetworkId;
+
+/**
+ * Service for administering the inventory of OpenFlow agents.
+ */
+public interface OFAgentAdminService {
+
+ /**
+ * Creates an OpenFlow agent for a given virtual network with given controllers.
+ *
+ * @param ofAgent the new ofagent
+ */
+ void createAgent(OFAgent ofAgent);
+
+ /**
+ * Updates the agent.
+ *
+ * @param ofAgent updated ofagent
+ */
+ void updateAgent(OFAgent ofAgent);
+
+ /**
+ * Removes the OpenFlow agent for the given virtual network.
+ *
+ * @param networkId virtual network identifier
+ */
+ void removeAgent(NetworkId networkId);
+
+ /**
+ * Starts the agent for the given network.
+ *
+ * @param networkId virtual network identifier
+ */
+ void startAgent(NetworkId networkId);
+
+ /**
+ * Stops the agent for the given network.
+ *
+ * @param networkId virtual network identifier
+ */
+ void stopAgent(NetworkId networkId);
+}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentEvent.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentEvent.java
new file mode 100644
index 0000000..7515a90
--- /dev/null
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentEvent.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2017-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.onosproject.ofagent.api;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes OFAgent event.
+ */
+public class OFAgentEvent extends AbstractEvent<OFAgentEvent.Type, OFAgent> {
+
+ private final OFController controller;
+
+ public enum Type {
+
+ /**
+ * Signifies that a new OFAgent is created.
+ */
+ OFAGENT_CREATED,
+
+ /**
+ * Signifies that the OFAgent is removed.
+ */
+ OFAGENT_REMOVED,
+
+ /**
+ * Signifies that the new external controller is added.
+ */
+ OFAGENT_CONTROLLER_ADDED,
+
+ /**
+ * Signifies that the external controller is removed.
+ */
+ OFAGENT_CONTROLLER_REMOVED,
+
+ /**
+ * Signifies that the OFAgent is started.
+ */
+ OFAGENT_STARTED,
+
+ /**
+ * Signifies that the OFAgent is stopped.
+ */
+ OFAGENT_STOPPED,
+ }
+
+ /**
+ * Creates an event of a given type for the specified ofagent and the current time.
+ *
+ * @param type ofagent event type
+ * @param ofAgent ofagent instance
+ */
+ public OFAgentEvent(OFAgentEvent.Type type, OFAgent ofAgent) {
+ super(type, ofAgent);
+ this.controller = null;
+ }
+
+ /**
+ * Creates an event of a given type for the specified ofagent and the updated controller.
+ *
+ * @param type ofagent event type
+ * @param ofAgent ofagent instance
+ * @param controller updated external controller
+ */
+ public OFAgentEvent(OFAgentEvent.Type type, OFAgent ofAgent, OFController controller) {
+ super(type, ofAgent);
+ this.controller = controller;
+ }
+
+ /**
+ * Returns the updated controller.
+ *
+ * @return updated controller; null if the event is not controller related
+ */
+ public OFController controller() {
+ return this.controller;
+ }
+}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentListener.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentListener.java
new file mode 100644
index 0000000..9cc7982
--- /dev/null
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017-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.onosproject.ofagent.api;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener for OFAgent events.
+ */
+public interface OFAgentListener extends EventListener<OFAgentEvent> {
+}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentService.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentService.java
index c2b5e47..17422e1 100644
--- a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentService.java
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentService.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.ofagent.api;
+import org.onosproject.event.ListenerService;
import org.onosproject.incubator.net.virtual.NetworkId;
import java.util.Set;
@@ -22,7 +23,9 @@
/**
* Service for administering OF agents for a virtual network.
*/
-public interface OFAgentService {
+public interface OFAgentService extends ListenerService<OFAgentEvent, OFAgentListener> {
+
+ String APPLICATION_NAME = "org.onosproject.ofagent";
/**
* Returns the OpenFlow agent list.
@@ -32,39 +35,10 @@
Set<OFAgent> agents();
/**
- * Creates an OpenFlow agent for a given virtual network with given controllers.
- *
- * @param networkId id of the virtual network
- * @param controllers list of controllers
- */
- void createAgent(NetworkId networkId, OFController... controllers);
-
- /**
- * Removes the OpenFlow agent for the given virtual network.
- *
- * @param networkId virtual network identifier
- */
- void removeAgent(NetworkId networkId);
-
- /**
- * Starts the agent for the given network.
- *
- * @param networkId virtual network identifier
- */
- void startAgent(NetworkId networkId);
-
- /**
- * Stops the agent for the given network.
- *
- * @param networkId virtual network identifier
- */
- void stopAgent(NetworkId networkId);
-
- /**
- * Returns if the agent of the given network is active or not.
+ * Returns the agent for the given network.
*
* @param networkId network id
- * @return true if the agent is active
+ * @return ofagent; null if no ofagent exists for the network
*/
- boolean isActive(NetworkId networkId);
+ OFAgent agent(NetworkId networkId);
}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentStore.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentStore.java
new file mode 100644
index 0000000..aa42716
--- /dev/null
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentStore.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017-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.onosproject.ofagent.api;
+
+import org.onosproject.incubator.net.virtual.NetworkId;
+import org.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of OpenFlow agent states; not intended for direct use.
+ */
+public interface OFAgentStore extends Store<OFAgentEvent, OFAgentStoreDelegate> {
+
+ /**
+ * Creates the new openflow agent.
+ *
+ * @param ofAgent the new ofagent
+ */
+ void createOfAgent(OFAgent ofAgent);
+
+ /**
+ * Updates the openflow agent.
+ *
+ * @param ofAgent the updated ofagent
+ */
+ void updateOfAgent(OFAgent ofAgent);
+
+ /**
+ * Removes the openflow agent for the supplied network ID.
+ *
+ * @param networkId virtual network identifier
+ * @return removed agent; null if remove failed
+ */
+ OFAgent removeOfAgent(NetworkId networkId);
+
+ /**
+ * Returns the openflow agent with the supplied network ID.
+ *
+ * @param networkId virtual network identifier
+ * @return ofagent; null if no ofagent exists for the network
+ */
+ OFAgent ofAgent(NetworkId networkId);
+
+ /**
+ * Returns all openflow agents.
+ *
+ * @return set of ofagents; empty set if no ofagents exist
+ */
+ Set<OFAgent> ofAgents();
+}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentStoreDelegate.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentStoreDelegate.java
new file mode 100644
index 0000000..16596fc
--- /dev/null
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFAgentStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017-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.onosproject.ofagent.api;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * OFAgent network store delegate abstraction.
+ */
+public interface OFAgentStoreDelegate extends StoreDelegate<OFAgentEvent> {
+}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitch.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitch.java
index 8ee6f64..b8cabf9 100644
--- a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitch.java
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitch.java
@@ -15,19 +15,19 @@
*/
package org.onosproject.ofagent.api;
-import org.onosproject.net.Device;
+import org.projectfloodlight.openflow.types.DatapathId;
/**
* Representation of virtual OpenFlow switch.
*/
-public interface OFSwitch extends OFSwitchService, OFControllerRoleService {
+public interface OFSwitch extends OFSwitchOperationService, OFControllerRoleService {
/**
* Returns the device information.
*
* @return virtual device
*/
- Device device();
+ DatapathId dpid();
/**
* Returns the capabilities of the switch.
@@ -35,11 +35,4 @@
* @return capabilities
*/
OFSwitchCapabilities capabilities();
-
- /**
- * Returns if the switch is connected to controllers or not.
- *
- * @return true if the switch is connected, false otherwise
- */
- boolean isConnected();
}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitchOperationService.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitchOperationService.java
new file mode 100644
index 0000000..6413cba
--- /dev/null
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitchOperationService.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2017-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.onosproject.ofagent.api;
+
+import io.netty.channel.Channel;
+import org.onosproject.net.Port;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.packet.InboundPacket;
+import org.projectfloodlight.openflow.protocol.OFMessage;
+
+/**
+ * Service for providing OpenFlow operations.
+ */
+public interface OFSwitchOperationService {
+
+ /**
+ * Processes a new port of the switch.
+ * It sends out FEATURE_REPLY message to the controllers.
+ *
+ * @param port virtual port
+ */
+ void processPortAdded(Port port);
+
+ /**
+ * Processes port link down.
+ * It sends out PORT_STATUS asynchronous message to the controllers.
+ *
+ * @param port virtual port
+ */
+ void processPortDown(Port port);
+
+ /**
+ * Processes port link down.
+ * It sends out PORT_STATUS asynchronous message to the controllers.
+ *
+ * @param port virtual port
+ */
+ void processPortUp(Port port);
+
+ /**
+ * Processes flow removed.
+ * It sends out FLOW_REMOVED asynchronous message to the controllers.
+ *
+ * @param flowRule removed flow rule
+ */
+ void processFlowRemoved(FlowRule flowRule);
+
+ /**
+ * Processes packet in.
+ * It sends out PACKET_IN asynchronous message to the controllers.
+ *
+ * @param packet inbound packet
+ */
+ void processPacketIn(InboundPacket packet);
+
+ /**
+ * Processes commands from the controllers that modify the state of the switch.
+ * Possible message types include PACKET_OUT, FLOW_MOD, GROUP_MOD,
+ * PORT_MOD, TABLE_MOD. These types of messages can be denied based on a
+ * role of the request controller.
+ *
+ * @param channel received channel
+ * @param msg command message received
+ */
+ void processControllerCommand(Channel channel, OFMessage msg);
+
+ /**
+ * Processes a stats request from the controllers.
+ * Targeted message type is MULTIPART_REQUEST with FLOW, PORT, GROUP,
+ * GROUP_DESC subtypes.
+ *
+ * @param channel received channel
+ * @param msg stats request message received
+ */
+ void processStatsRequest(Channel channel, OFMessage msg);
+
+ /**
+ * Processes a role request from the controllers.
+ * Targeted message type is ROLE_REQUEST.
+ *
+ * @param channel received channel
+ * @param msg role request message received
+ */
+ void processRoleRequest(Channel channel, OFMessage msg);
+
+ /**
+ * Processes a features request from the controllers.
+ *
+ * @param channel received channel
+ * @param msg received features request
+ */
+ void processFeaturesRequest(Channel channel, OFMessage msg);
+
+ /**
+ * Processes LLDP packets from the controller.
+ *
+ * @param channel received channel
+ * @param msg packet out message with lldp
+ */
+ void processLldp(Channel channel, OFMessage msg);
+
+ /**
+ * Sends hello to the controller.
+ *
+ * @param channel received channel
+ */
+ void sendOfHello(Channel channel);
+
+ /**
+ * Processes echo request from the controllers.
+ *
+ * @param channel received channel
+ * @param msg echo request message
+ */
+ void processEchoRequest(Channel channel, OFMessage msg);
+}
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitchService.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitchService.java
index 4f33b51..898aede 100644
--- a/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitchService.java
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/api/OFSwitchService.java
@@ -15,125 +15,27 @@
*/
package org.onosproject.ofagent.api;
-import io.netty.channel.Channel;
-import org.onosproject.net.Port;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.packet.InboundPacket;
-import org.projectfloodlight.openflow.protocol.OFMessage;
+import org.onosproject.incubator.net.virtual.NetworkId;
+
+import java.util.Set;
/**
- * Service providing OpenFlow switch operations.
+ * Service for providing virtual OpenFlow switch information.
*/
public interface OFSwitchService {
/**
- * Handles the switch starts.
- */
- void started();
-
- /**
- * Handles the switch stops.
- */
- void stopped();
-
- /**
- * Processes a new port of the switch.
- * It sends out FEATURE_REPLY message to the controllers.
+ * Returns all openflow switches that OF agent service manages.
*
- * @param port virtual port
+ * @return set of openflow switches; empty set if no openflow switches exist
*/
- void processPortAdded(Port port);
+ Set<OFSwitch> ofSwitches();
/**
- * Processes port link down.
- * It sends out PORT_STATUS asynchronous message to the controllers.
+ * Returns all openflow switches for the specified network.
*
- * @param port virtual port
+ * @param networkId network id
+ * @return set of openflow switches; empty set if no devices exist on the network
*/
- void processPortDown(Port port);
-
- /**
- * Processes port link down.
- * It sends out PORT_STATUS asynchronous message to the controllers.
- *
- * @param port virtual port
- */
- void processPortUp(Port port);
-
- /**
- * Processes flow removed.
- * It sends out FLOW_REMOVED asynchronous message to the controllers.
- *
- * @param flowRule removed flow rule
- */
- void processFlowRemoved(FlowRule flowRule);
-
- /**
- * Processes packet in.
- * It sends out PACKET_IN asynchronous message to the controllers.
- *
- * @param packet inbound packet
- */
- void processPacketIn(InboundPacket packet);
-
- /**
- * Processes commands from the controllers that modify the state of the switch.
- * Possible message types include PACKET_OUT, FLOW_MOD, GROUP_MOD,
- * PORT_MOD, TABLE_MOD. These types of messages can be denied based on a
- * role of the request controller.
- *
- * @param channel received channel
- * @param msg command message received
- */
- void processControllerCommand(Channel channel, OFMessage msg);
-
- /**
- * Processes a stats request from the controllers.
- * Targeted message type is MULTIPART_REQUEST with FLOW, PORT, GROUP,
- * GROUP_DESC subtypes.
- *
- * @param channel received channel
- * @param msg stats request message received
- */
- void processStatsRequest(Channel channel, OFMessage msg);
-
- /**
- * Processes a role request from the controllers.
- * Targeted message type is ROLE_REQUEST.
- *
- * @param channel received channel
- * @param msg role request message received
- */
- void processRoleRequest(Channel channel, OFMessage msg);
-
- /**
- * Processes a features request from the controllers.
- *
- * @param channel received channel
- * @param msg received features request
- */
- void processFeaturesRequest(Channel channel, OFMessage msg);
-
- /**
- * Processes LLDP packets from the controller.
- *
- * @param channel received channel
- * @param msg packet out message with lldp
- */
- void processLldp(Channel channel, OFMessage msg);
-
- /**
- * Sends hello to the controller.
- *
- * @param channel received channel
- */
- void sendOfHello(Channel channel);
-
- /**
- * Processes echo request from the controllers.
- *
- * @param channel received channel
- * @param msg echo request message
- */
- void processEchoRequest(Channel channel, OFMessage msg);
+ Set<OFSwitch> ofSwitches(NetworkId networkId);
}