Added the function to remove the AVOID poloicy.
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
index 92aebb3..34961e5 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -160,7 +160,8 @@
POLICY_REMOVE2,
TUNNEL_REMOVE1,
TUNNEL_REMOVE2,
- POLICY_AVOID
+ POLICY_AVOID,
+ POLICY_REMOVE3
}
private TEST_MODE testMode = TEST_MODE.NO_TEST;
@@ -274,8 +275,8 @@
}
});
- //testMode = TEST_MODE.POLICY_AVOID;
- //testTask.reschedule(20, TimeUnit.SECONDS);
+ testMode = TEST_MODE.POLICY_AVOID;
+ testTask.reschedule(30, TimeUnit.SECONDS);
}
@Override
@@ -2228,8 +2229,14 @@
createPolicy(pid, srcMac, dstMac, etherType, srcIp, dstIp, ipProto,
srcPort, dstPort, priority, srcNode, dstNode, nodesToAvoid, linksToAvoid);
+ testMode = TEST_MODE.POLICY_REMOVE3;
+ testTask.reschedule(10, TimeUnit.SECONDS);
}
+ else if (testMode == TEST_MODE.POLICY_REMOVE3) {
+ String pid = "p1";
+ removePolicy(pid);
+ }
}
private void printEcmpPaths(List<Path> ecmpPaths) {
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java
index 94f18ad..1658b1c 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java
@@ -115,6 +115,32 @@
}
/**
+ * Remove rules from the ACL table
+ *
+ * @param routes ACL rule information
+ */
+ protected void removeAclRules(List<TunnelRouteInfo> routes) {
+ List<Action> actions = new ArrayList<>();
+ int gropuId = 0; // dummy group ID
+ GroupAction groupAction = new GroupAction();
+ groupAction.setGroupId(gropuId);
+ actions.add(groupAction);
+
+ for (TunnelRouteInfo route : routes) {
+
+ MatchAction matchAction = new MatchAction(
+ srManager.getMatchActionId(),
+ new SwitchPort((new Dpid(route.getSrcSwDpid())).value(), (long)0), match, priority,
+ actions);
+ MatchActionOperationEntry maEntry =
+ new MatchActionOperationEntry(Operator.REMOVE, matchAction);
+
+ srManager.executeMatchActionOpEntry(maEntry);
+ }
+ }
+
+
+ /**
* Get the policy ID
*
* @return policy ID
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyAvoid.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyAvoid.java
index 608b28f..bba968b 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyAvoid.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyAvoid.java
@@ -22,6 +22,7 @@
private Switch dstSwitch;
private List<String> dpidListToAvoid;
private List<Link> linkListToAvoid;
+ private SegmentRoutingTunnel tunnel;
public SegmentRoutingPolicyAvoid(PolicyNotification policyNotication) {
super(policyNotication);
@@ -57,14 +58,14 @@
labelStack.add(Integer.valueOf(srManager.getMplsLabel(dstDpid)));
//String nodeToAvoid = srManager.getMplsLabel(switchToAvoid.getDpid().toString());
OptimizeLabelStack(labelStack);
- SegmentRoutingTunnel avoidTunnel = new SegmentRoutingTunnel(
+ tunnel = new SegmentRoutingTunnel(
srManager, "avoid-0", labelStack);
- if (avoidTunnel.createTunnel()) {
+ if (tunnel.createTunnel()) {
//tunnelTable.put(tunnelId, srTunnel);
//TunnelNotification tunnelNotification =
// new TunnelNotification(srTunnel);
//tunnelEventChannel.addEntry(tunnelId, tunnelNotification);
- populateAclRule(avoidTunnel.getRoutes());
+ populateAclRule(tunnel.getRoutes());
}
else {
log.warn("Failed to create a tunnel for Policy Avoid");
@@ -75,6 +76,18 @@
return true;
}
+ @Override
+ public boolean removePolicy() {
+ if (tunnel.removeTunnel()) {
+ removeAclRules(tunnel.getRoutes());
+ return true;
+ }
+ else {
+ log.warn("Error in removing an avoid policy");
+ return false;
+ }
+ }
+
/**
* Optimize the label stack removing unnecessary label IDs, resulting the
* same path. It modifies the list given directly.
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
index 27b98fd..ab3f653 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
@@ -1,16 +1,8 @@
package net.onrc.onos.apps.segmentrouting;
-import java.util.ArrayList;
import java.util.List;
-import net.onrc.onos.core.matchaction.MatchAction;
-import net.onrc.onos.core.matchaction.MatchActionOperationEntry;
-import net.onrc.onos.core.matchaction.MatchActionOperations.Operator;
-import net.onrc.onos.core.matchaction.action.Action;
-import net.onrc.onos.core.matchaction.action.GroupAction;
import net.onrc.onos.core.matchaction.match.PacketMatch;
-import net.onrc.onos.core.util.Dpid;
-import net.onrc.onos.core.util.SwitchPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,21 +41,6 @@
@Override
public boolean removePolicy() {
- List<Action> actions = new ArrayList<>();
- int gropuId = 0; // dummy group ID
- GroupAction groupAction = new GroupAction();
- groupAction.setGroupId(gropuId);
- actions.add(groupAction);
-
- /*
- MatchAction matchAction = new MatchAction(
- srManager.getMatchActionId(),
- new SwitchPort((long) 0, (short) 0), match, priority,
- actions);
- MatchActionOperationEntry maEntry =
- new MatchActionOperationEntry(Operator.REMOVE, matchAction);
- */
-
SegmentRoutingTunnel tunnel = srManager.getTunnelInfo(tunnelId);
if (tunnel == null) {
log.warn("Cannot find the tunnel {} for the policy {}", tunnelId,
@@ -71,36 +48,7 @@
return false;
}
List<TunnelRouteInfo> routes = tunnel.getRoutes();
-
- for (TunnelRouteInfo route : routes) {
-
- MatchAction matchAction = new MatchAction(
- srManager.getMatchActionId(),
- new SwitchPort((new Dpid(route.getSrcSwDpid())).value(), (long)0), match, priority,
- actions);
- MatchActionOperationEntry maEntry =
- new MatchActionOperationEntry(Operator.REMOVE, matchAction);
-
- srManager.executeMatchActionOpEntry(maEntry);
-
- /*
- IOF13Switch sw13 = srManager.getIOF13Switch(route.getSrcSwDpid());
- if (sw13 == null) {
- log.warn("Cannt find the switch {}", route.getSrcSwDpid());
- return false;
- }
- else {
- srManager.printMatchActionOperationEntry(sw13, maEntry);
- try {
- sw13.pushFlow(maEntry);
- } catch (IOException e) {
- e.printStackTrace();
- log.debug("policy remove failed due to pushFlow() exception");
- return false;
- }
- }
- */
- }
+ removeAclRules(routes);
return true;
}