Added CLI to flush flow rules installed by cordvtn
Might be useful to refresh data plane with most recent status of Neutron
and VMs by flushing all existing rules and pushing network config again
And also removed read configuration during activation since leadership
service does not work as expected during app activation
Change-Id: Ia22fe02d25a61126f3e6df59fc5ad4d065f89f18
diff --git a/src/main/java/org/onosproject/cordvtn/CordVtnNodeManager.java b/src/main/java/org/onosproject/cordvtn/CordVtnNodeManager.java
index bcd76bc..34f8b9c 100644
--- a/src/main/java/org/onosproject/cordvtn/CordVtnNodeManager.java
+++ b/src/main/java/org/onosproject/cordvtn/CordVtnNodeManager.java
@@ -237,7 +237,6 @@
deviceService.addListener(deviceListener);
configService.addListener(configListener);
- readConfiguration();
}
@Deactivate
@@ -315,6 +314,13 @@
}
/**
+ * Flush flows installed by cordvtn.
+ */
+ public void flushRules() {
+ ruleInstaller.flushRules();
+ }
+
+ /**
* Returns if current node state saved in nodeStore is COMPLETE or not.
*
* @param node cordvtn node
diff --git a/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java b/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java
index f3877e0..808f7c6 100644
--- a/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java
+++ b/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java
@@ -172,6 +172,13 @@
}
/**
+ * Flush flows installed by this application.
+ */
+ public void flushRules() {
+ flowRuleService.getFlowRulesById(appId).forEach(flowRule -> processFlowRule(false, flowRule));
+ }
+
+ /**
* Populates basic rules that connect a VM to the other VMs in the system.
*
* @param host host
diff --git a/src/main/java/org/onosproject/cordvtn/cli/CordVtnFlushRules.java b/src/main/java/org/onosproject/cordvtn/cli/CordVtnFlushRules.java
new file mode 100644
index 0000000..9673662
--- /dev/null
+++ b/src/main/java/org/onosproject/cordvtn/cli/CordVtnFlushRules.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 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.cordvtn.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cordvtn.CordVtnNodeManager;
+
+/**
+ * Deletes nodes from the service.
+ */
+@Command(scope = "onos", name = "cordvtn-flush-rules",
+ description = "Flush flow rules installed by CORD VTN")
+public class CordVtnFlushRules extends AbstractShellCommand {
+
+ @Override
+ protected void execute() {
+ CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class);
+ nodeManager.flushRules();
+ print("Successfully flushed");
+ }
+}
diff --git a/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 9a2854f..dc9ecdb 100644
--- a/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -28,5 +28,8 @@
<command>
<action class="org.onosproject.cordvtn.cli.CordVtnNodeCheckCommand"/>
</command>
+ <command>
+ <action class="org.onosproject.cordvtn.cli.CordVtnFlushRules"/>
+ </command>
</command-bundle>
</blueprint>