Fixed CLI router command
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 cb5fa32..668ceaa 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -31,6 +31,7 @@
import net.floodlightcontroller.util.MACAddress;
import net.onrc.onos.api.packet.IPacketListener;
import net.onrc.onos.api.packet.IPacketService;
+import net.onrc.onos.apps.segmentrouting.web.SegmentRoutingWebRoutable;
import net.onrc.onos.core.flowprogrammer.IFlowPusherService;
import net.onrc.onos.core.intent.Path;
import net.onrc.onos.core.main.config.IConfigInfoService;
@@ -69,6 +70,7 @@
import net.onrc.onos.core.util.Dpid;
import net.onrc.onos.core.util.IPv4Net;
import net.onrc.onos.core.util.SwitchPort;
+import net.floodlightcontroller.restserver.IRestApiService;
import org.json.JSONArray;
import org.json.JSONException;
@@ -88,7 +90,7 @@
private IPacketService packetService;
private MutableTopology mutableTopology;
private ConcurrentLinkedQueue<IPv4> ipPacketQueue;
-
+ private IRestApiService restApi;
private List<ArpEntry> arpEntries;
private ArpHandler arpHandler;
private GenericIpHandler ipHandler;
@@ -105,9 +107,6 @@
private ConcurrentLinkedQueue<TopologyEvents> topologyEventQueue;
private HashMap<Integer, HashMap<String, PolicyRouteInfo>> stitchInfo;
private HashMap<Integer, HashMap<String, Integer>> tunnelGroupMap;
- private HashMap<Integer, PolicyInfo> policyTable;
-
- private int testMode = 0;
private int numOfEvents = 0;
private int numOfEventProcess = 0;
@@ -116,11 +115,6 @@
private final int DELAY_TO_ADD_LINK = 10;
private final int MAX_NUM_LABELS = 3;
- private final int POLICY_ADD1 = 1;
- private final int POLICY_ADD2 = 2;
- private final int POLICY_REMOVE1 = 3;
- private final int POLICY_REMOVE2 = 4;
-
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
// TODO Auto-generated method stub
@@ -143,6 +137,7 @@
l.add(IPacketService.class);
l.add(IFlowPusherService.class);
l.add(ITopologyService.class);
+ l.add(IRestApiService.class);
return l;
@@ -166,7 +161,7 @@
stitchInfo = new HashMap<Integer, HashMap<String, PolicyRouteInfo>>();
packetService = context.getServiceImpl(IPacketService.class);
tunnelGroupMap = new HashMap<Integer, HashMap<String, Integer>>();
- policyTable = new HashMap<Integer, PolicyInfo>();
+ restApi = context.getServiceImpl(IRestApiService.class);
packetService.registerPacketListener(this);
topologyService.addListener(this, false);
@@ -177,6 +172,7 @@
@Override
public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
ScheduledExecutorService ses = threadPool.getScheduledExecutor();
+ restApi.addRestletRoutable(new SegmentRoutingWebRoutable());
discoveryTask = new SingletonTask(ses, new Runnable() {
@Override
@@ -199,11 +195,11 @@
}
});
- //policy routing test task
- testMode = POLICY_ADD1;
- testTask.reschedule(20, TimeUnit.SECONDS);
+ // policy routing test task
+ //testTask.reschedule(20, TimeUnit.SECONDS);
}
+
@Override
public void receive(Switch sw, Port inPort, Ethernet payload) {
if (payload.getEtherType() == Ethernet.TYPE_ARP)
@@ -683,6 +679,7 @@
}
+
/**
* This class is used only for link recovery optimization in
* modifyEcmpRoutingRules() function.
@@ -1160,60 +1157,46 @@
return true;
}
- public void removeTunnel(int tunnelId) {
-
- }
-
-
- class PolicyInfo {
-
- int policyId;
- PacketMatch match;
- int priority;
- int tunnelId;
-
- PolicyInfo(int pid, PacketMatch match, int priority, int tid) {
- this.policyId = pid;
- this.match = match;
- this.priority = priority;
- this.tunnelId = tid;
- }
- }
-
/**
* Set policy table for policy routing
*
* @param sw
* @param mplsLabel
*/
- public void setPolicyTable(int pid, MACAddress srcMac, MACAddress dstMac,
+ public void setPolicyTable(MACAddress srcMac, MACAddress dstMac,
Short etherType, IPv4Net srcIp, IPv4Net dstIp, Byte ipProto,
- Short srcTcpPort, Short dstTcpPort, int priority, int tid) {
+ Short srcTcpPort, Short dstTcpPort, int tid) {
HashMap<String, PolicyRouteInfo> routeInfo = stitchInfo.get(Integer.valueOf(tid));
HashMap<String, Integer> switchGroupPair = tunnelGroupMap.get(Integer.valueOf(tid));
-
- PacketMatchBuilder packetBuilder = new PacketMatchBuilder();
-
- if (srcMac != null)
- packetBuilder.setSrcMac(srcMac);
- if (dstMac != null)
- packetBuilder.setDstMac(dstMac);
- if (etherType != null)
- packetBuilder.setEtherType(etherType);
- if (srcIp != null)
- packetBuilder.setSrcIp(srcIp.address(), srcIp.prefixLen());
- if (dstIp != null)
- packetBuilder.setDstIp(dstIp.address(), dstIp.prefixLen());
- if (ipProto != null)
- packetBuilder.setIpProto(ipProto);
- if (srcTcpPort > 0)
- packetBuilder.setSrcTcpPort(srcTcpPort);
- if (dstTcpPort > 0)
- packetBuilder.setDstTcpPort(dstTcpPort);
- PacketMatch packetMatch = packetBuilder.build();
-
for (String srcDpid: routeInfo.keySet()) {
+
+ PacketMatchBuilder packetBuilder = new PacketMatchBuilder();
+
+ if (srcMac != null)
+ packetBuilder.setSrcMac(srcMac);
+ if (dstMac != null)
+ packetBuilder.setDstMac(dstMac);
+ if (etherType != null) {
+ packetBuilder.setEtherType(etherType);
+ }
+ if (srcIp != null) {
+ packetBuilder.setSrcIp(srcIp.address(), srcIp.prefixLen());
+ }
+ if (dstIp != null) {
+ packetBuilder.setDstIp(dstIp.address(), dstIp.prefixLen());
+ }
+ if (ipProto != null) {
+ packetBuilder.setIpProto(ipProto);
+ }
+ if (srcTcpPort > 0) {
+ packetBuilder.setSrcTcpPort(srcTcpPort);
+ }
+ if (dstTcpPort > 0) {
+ packetBuilder.setDstTcpPort(dstTcpPort);
+ }
+ PacketMatch policyMatch = packetBuilder.build();
+
List<Action> actions = new ArrayList<>();
GroupAction groupAction = new GroupAction();
int gropuId = switchGroupPair.get(srcDpid);
@@ -1222,8 +1205,7 @@
MatchAction matchAction = new MatchAction(new MatchActionId(
matchActionId++),
- new SwitchPort((long) 0, (short) 0), packetMatch, priority,
- actions);
+ new SwitchPort((long) 0, (short) 0), policyMatch, actions);
MatchActionOperationEntry maEntry =
new MatchActionOperationEntry(Operator.ADD, matchAction);
@@ -1236,68 +1218,9 @@
sw13.pushFlow(maEntry);
} catch (IOException e) {
e.printStackTrace();
- log.debug("Policy was not set due to pushFlow() error");
}
}
}
-
- PolicyInfo policyInfo = new PolicyInfo(pid, packetMatch, priority, tid);
- policyTable.put(Integer.valueOf(pid), policyInfo);
- }
-
- /**
- * Remove all policies applied to specific tunnel.
- *
- * @param srcMac
- * @param dstMac
- * @param etherType
- * @param srcIp
- * @param dstIp
- * @param ipProto
- * @param srcTcpPort
- * @param dstTcpPort
- * @param tid
- */
- public void removePolicy(int pid) {
-
- PolicyInfo policyInfo = policyTable.get(Integer.valueOf(pid));
- PacketMatch policyMatch = policyInfo.match;
- int tid = policyInfo.tunnelId;
- int priority = policyInfo.priority;
-
- 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(new MatchActionId(
- matchActionId++),
- new SwitchPort((long) 0, (short) 0), policyMatch, priority,
- actions);
- MatchActionOperationEntry maEntry =
- new MatchActionOperationEntry(Operator.REMOVE, matchAction);
-
- HashMap<String, Integer> groupInfo = tunnelGroupMap.get(
- Integer.valueOf(tid));
-
- for (String dpid: groupInfo.keySet()) {
- IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
- getSwId(dpid));
-
- if (sw13 != null) {
- printMatchActionOperationEntry(sw13, maEntry);
- try {
- sw13.pushFlow(maEntry);
- } catch (IOException e) {
- e.printStackTrace();
- log.debug("policy remove failed due to pushFlow() exception");
- return;
- }
- }
- }
-
- log.debug("Policy {} is removed.", pid);
}
/**
@@ -1382,60 +1305,19 @@
private void runTest() {
- if (testMode == POLICY_ADD1) {
- String[] routeArray = {"101", "105", "110"};
- List<String> routeList = new ArrayList<String>();
- for (int i = 0; i < routeArray.length; i++)
- routeList.add(routeArray[i]);
+ String[] routeArray = {"101", "102", "103", "104", "105", "108", "110"};
+ List<String> routeList = new ArrayList<String>();
+ for (int i = 0; i < routeArray.length; i++)
+ routeList.add(routeArray[i]);
- if (createTunnel(1, routeList)) {
- IPv4Net srcIp = new IPv4Net("10.0.1.1/24");
- IPv4Net dstIp = new IPv4Net("10.1.2.1/24");
+ if (createTunnel(1, routeList)) {
+ IPv4Net srcIp = new IPv4Net("10.0.1.1/24");
+ IPv4Net dstIp = new IPv4Net("10.1.2.1/24");
- log.debug("Set the policy 1");
- this.setPolicyTable(1, null, null, Ethernet.TYPE_IPV4, srcIp,
- dstIp, IPv4.PROTOCOL_ICMP, (short)-1, (short)-1, 10000,
- 1);
- testMode = POLICY_ADD2;
- testTask.reschedule(10, TimeUnit.SECONDS);
- }
- else {
- // retry it
- testTask.reschedule(5, TimeUnit.SECONDS);
- }
+ this.setPolicyTable(null, null, Ethernet.TYPE_IPV4, srcIp, dstIp, IPv4.PROTOCOL_ICMP, (short)-1, (short)-1, 1);
}
- else if (testMode == POLICY_ADD2) {
- String[] routeArray = {"101", "102", "103", "104", "105", "108",
- "110"};
- List<String> routeList = new ArrayList<String>();
- for (int i = 0; i < routeArray.length; i++)
- routeList.add(routeArray[i]);
-
- if (createTunnel(2, routeList)) {
- IPv4Net srcIp = new IPv4Net("10.0.1.1/24");
- IPv4Net dstIp = new IPv4Net("10.1.2.1/24");
-
- log.debug("Set the policy 2");
- this.setPolicyTable(2, null, null, Ethernet.TYPE_IPV4, srcIp,
- dstIp, IPv4.PROTOCOL_ICMP, (short)-1, (short)-1, 20000,
- 2);
- testMode = POLICY_REMOVE1;
- testTask.reschedule(10, TimeUnit.SECONDS);
- }
- else {
- log.debug("Retry it");
- testTask.reschedule(5, TimeUnit.SECONDS);
- }
- }
- else if (testMode == POLICY_REMOVE1){
- log.debug("Remove the policy 1");
- this.removePolicy(2);
- testMode = POLICY_REMOVE2;
- testTask.reschedule(10, TimeUnit.SECONDS);
- }
- else if (testMode == POLICY_REMOVE2) {
- log.debug("Remove the policy 2");
- this.removePolicy(1);
+ else {
+ testTask.reschedule(5, TimeUnit.SECONDS);
}
}
@@ -1509,9 +1391,7 @@
}
- /**
- * Strore policy routing info
- */
+
class PolicyRouteInfo {
String srcSwDpid;
@@ -1552,6 +1432,7 @@
}
}
+
/**
*
*
@@ -1669,6 +1550,8 @@
}
+
+
/**
* Debugging function to print out the Match Action Entry
* @param sw13
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java
index a25d4de..73c1334 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterPortInfo.java
@@ -13,12 +13,10 @@
public class SegmentRouterPortInfo {
//TODO set attributes to private and provide setter and getter.
public String subnetIp= null;
- //private int portNo;
public Port port = null;
public SegmentRouterPortInfo(String ssubnets, Port pport){
this.port = pport;
- //this.portNo = portNo;
this.subnetIp = ssubnets;
}