return false;
}
+ private String getPortUuid(Node node, String name, String bridgeUUID) throws Exception {
+ OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
+ Bridge bridge = (Bridge)ovsdbTable.getRow(node, Bridge.NAME.getName(), bridgeUUID);
+ if (bridge != null) {
+ Set<UUID> ports = bridge.getPorts();
+ for (UUID portUUID : ports) {
+ Port port = (Port)ovsdbTable.getRow(node, Port.NAME.getName(), portUUID.toString());
+ if (port != null && port.getName().equalsIgnoreCase(name)) return portUUID.toString();
+ }
+ }
+ return null;
+ }
+
private Status addTunnelPort (Node node, String tunnelType, InetAddress src, InetAddress dst) {
try {
String bridgeUUID = null;
}
}
+ /* delete port from ovsdb port table */
+ private Status deletePort(Node node, String bridgeName, String portName) {
+ try {
+ String bridgeUUID = null;
+ OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
+ Map<String, org.opendaylight.ovsdb.lib.table.internal.Table<?>> bridgeTable = ovsdbTable.getRows(node, Bridge.NAME.getName());
+ if (bridgeTable != null) {
+ for (String uuid : bridgeTable.keySet()) {
+ Bridge bridge = (Bridge)bridgeTable.get(uuid);
+ if (bridge.getName().equals(bridgeName)) {
+ bridgeUUID = uuid;
+ break;
+ }
+ }
+ }
+ if (bridgeUUID == null) {
+ logger.debug("Could not find Bridge {} in {}", bridgeName, node);
+ return new Status(StatusCode.SUCCESS);
+ }
+
+ String portUUID = this.getPortUuid(node, portName, bridgeUUID);
+ Status status = new Status(StatusCode.SUCCESS);
+ if (portUUID != null) {
+ status = ovsdbTable.deleteRow(node, Port.NAME.getName(), portUUID);
+ if (!status.isSuccess()) {
+ logger.error("Failed to delete port {} in {} status : {}", portName, bridgeUUID,
+ status);
+ return status;
+ }
+ logger.debug("Port {} delete status : {}", portName, status);
+ }
+ return status;
+ } catch (Exception e) {
+ logger.error("Exception in deletePort", e);
+ return new Status(StatusCode.INTERNALERROR);
+ }
+ }
+
+ private Status deleteTunnelPort(Node node, String tunnelType, InetAddress src, InetAddress dst) {
+ String tunnelBridgeName = AdminConfigManager.getManager().getIntegrationBridgeName();
+ String portName = getTunnelName(tunnelType, dst);
+ Status status = deletePort(node, tunnelBridgeName, portName);
+ return status;
+ }
+
private void programLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
/*
* Table(0) Rule #3
* Action:Action: Set Tunnel ID and GOTO Local Table (5)
*/
- writeLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac);
+ handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, true);
/*
* Table(0) Rule #4
* Action: Drop w/ a low priority
*/
- writeDropSrcIface(dpid, localPort);
+ handleDropSrcIface(dpid, localPort, true);
/*
* Table(2) Rule #1
* table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
*/
- writeLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac);
+ handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, true);
/*
* Table(2) Rule #2
* actions=output:2,3,4,5
*/
- writeLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort);
+ handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, true);
/*
* TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
* table=1,priority=8192,tun_id=0x5 actions=goto_table:2
*/
- writeTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId);
+ handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, true);
/*
* Table(2) Rule #3
* table=2,priority=8192,tun_id=0x5 actions=drop
*/
- writeLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId);
+ handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, true);
+ }
+
+ private void removeLocalBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long localPort) {
+ /*
+ ** Table(0) Rule #3
+ ** ----------------
+ ** Match: VM sMac and Local Ingress Port
+ ** Action:Action: Set Tunnel ID and GOTO Local Table (5)
+ **/
+
+ handleLocalInPort(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_1_ISOLATE_TENANT, segmentationId, localPort, attachedMac, false);
+
+ /*
+ ** Table(0) Rule #4
+ ** ----------------
+ ** Match: Drop any remaining Ingress Local VM Packets
+ ** Action: Drop w/ a low priority
+ **/
+
+ handleDropSrcIface(dpid, localPort, false);
+
+ /*
+ ** Table(2) Rule #1
+ ** ----------------
+ ** Match: Match TunID and Destination DL/dMAC Addr
+ ** Action: Output Port
+ ** table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
+ **/
+
+ handleLocalUcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, attachedMac, false);
+
+ /*
+ ** Table(2) Rule #2
+ ** ----------------
+ ** Match: Tunnel ID and dMAC (::::FF:FF)
+ ** table=2,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+ ** actions=output:2,3,4,5
+ **/
+
+ handleLocalBcastOut(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, localPort, false);
}
private void programLocalIngressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
* Table(0) Rule #2
* ----------------
* Match: Ingress Port, Tunnel ID
- * Action: GOTO Local Table (10)
+ * Action: GOTO Local Table (20)
*/
- writeTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort);
+ handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
/*
* Table(1) Rule #2
* actions=output:10,output:11,goto_table:2
*/
- writeTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort);
+ handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, true);
}
* actions=output:11,goto_table:2
*/
- writeTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac);
+ handleTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac, true);
+ }
+
+ private void removeRemoteEgressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
+ /*
+ ** Table(1) Rule #1
+ ** ----------------
+ ** Match: Drop any remaining Ingress Local VM Packets
+ ** Action: Drop w/ a low priority
+ ** -------------------------------------------
+ ** table=1,tun_id=0x5,dl_dst=00:00:00:00:00:08 \
+ ** actions=output:11,goto_table:2
+ **/
+
+ handleTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac, false);
+ }
+
+ /* Remove tunnel rules if last node in this tenant network */
+ private void removePerTunnelRules(Node node, Long dpid, String segmentationId, long tunnelOFPort) {
+ /*
+ ** TODO : Optimize the following 2 writes to be restricted only for the very first port known in a segment.
+ **/
+ /*
+ ** Table(1) Rule #3
+ ** ----------------
+ ** Match: Any remaining Ingress Local VM Packets
+ ** Action: Drop w/ a low priority
+ ** -------------------------------------------
+ ** table=1,priority=8192,tun_id=0x5 actions=goto_table:2
+ **/
+
+ handleTunnelMiss(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, false);
+
+ /*
+ ** Table(2) Rule #3
+ ** ----------------
+ ** Match: Any Remaining Flows w/a TunID
+ ** Action: Drop w/ a low priority
+ ** table=2,priority=8192,tun_id=0x5 actions=drop
+ **/
+
+ handleLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId, false);
+
+ /*
+ ** Table(0) Rule #2
+ ** ----------------
+ ** Match: Ingress Port, Tunnel ID
+ ** Action: GOTO Local Table (10)
+ **/
+
+ handleTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
+
+ /*
+ ** Table(1) Rule #2
+ ** ----------------
+ ** Match: Match Tunnel ID and L2 ::::FF:FF Flooding
+ ** Action: Flood to selected destination TEPs
+ ** -------------------------------------------
+ ** table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+ ** actions=output:10,output:11,goto_table:2
+ **/
+
+ handleTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, false);
}
private Long getIntegrationBridgeOFDPID (Node node) {
}
}
+ private void removeLocalRules (String networkType, String segmentationId, Node node, Interface intf) {
+ try {
+ Long dpid = this.getIntegrationBridgeOFDPID(node);
+ if (dpid == 0L) {
+ logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
+ return;
+ }
+
+ Set<BigInteger> of_ports = intf.getOfport();
+ if (of_ports == null || of_ports.size() <= 0) {
+ logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
+ return;
+ }
+ long localPort = ((BigInteger)of_ports.toArray()[0]).longValue();
+
+ Map<String, String> externalIds = intf.getExternal_ids();
+ if (externalIds == null) {
+ logger.error("No external_ids seen in {}", intf);
+ return;
+ }
+
+ String attachedMac = externalIds.get(TenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ if (attachedMac == null) {
+ logger.error("No AttachedMac seen in {}", intf);
+ return;
+ }
+
+ /* Program local rules based on network type */
+ if (networkType.equalsIgnoreCase("gre") ||
+ networkType.equalsIgnoreCase("vxlan")) {
+ logger.debug("Remove local bridge rules for interface {}", intf.getName());
+ removeLocalBridgeRules(node, dpid, segmentationId, attachedMac, localPort);
+ }
+ } catch (Exception e) {
+ logger.error("Exception in removing Local Rules for "+intf+" on "+node, e);
+ }
+ }
+
+
private void programTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
Interface intf, boolean local) {
try {
if (!local) {
programRemoteEgressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
}
- programLocalIngressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
+ logger.trace("program local ingress tunnel rules: node" + node.getNodeIDString() + " intf " + intf.getName());
+ if (local) {
+ programLocalIngressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
+ }
+ return;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.error("", e);
+ }
+ }
+
+ private void removeTunnelRules (String tunnelType, String segmentationId, InetAddress dst, Node node,
+ Interface intf, boolean local, boolean isLastInstanceOnNode) {
+ try {
+
+ Long dpid = this.getIntegrationBridgeOFDPID(node);
+ if (dpid == 0L) {
+ logger.debug("Openflow Datapath-ID not set for the integration bridge in {}", node);
+ return;
+ }
+ OVSDBConfigService ovsdbTable = (OVSDBConfigService) ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
+
+ Set<BigInteger> of_ports = intf.getOfport();
+ if (of_ports == null || of_ports.size() <= 0) {
+ logger.error("Could NOT Identify OF value for port {} on {}", intf.getName(), node);
+ return;
+ }
+ long localPort = ((BigInteger)of_ports.toArray()[0]).longValue();
+
+ Map<String, String> externalIds = intf.getExternal_ids();
+ if (externalIds == null) {
+ logger.error("No external_ids seen in {}", intf);
+ return;
+ }
+
+ String attachedMac = externalIds.get(TenantNetworkManager.EXTERNAL_ID_VM_MAC);
+ if (attachedMac == null) {
+ logger.error("No AttachedMac seen in {}", intf);
+ return;
+ }
+
+ Map<String, org.opendaylight.ovsdb.lib.table.internal.Table<?>> intfs = ovsdbTable.getRows(node, Interface.NAME.getName());
+ if (intfs != null) {
+ for (org.opendaylight.ovsdb.lib.table.internal.Table<?> row : intfs.values()) {
+ Interface tunIntf = (Interface)row;
+ if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
+ of_ports = tunIntf.getOfport();
+ if (of_ports == null || of_ports.size() <= 0) {
+ logger.error("Could NOT Identify Tunnel port {} on {}", tunIntf.getName(), node);
+ continue;
+ }
+ long tunnelOFPort = ((BigInteger)of_ports.toArray()[0]).longValue();
+
+ if (tunnelOFPort == -1) {
+ logger.error("Could NOT Identify Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
+ return;
+ }
+ logger.debug("Identified Tunnel port {} -> OF ({}) on {}", tunIntf.getName(), tunnelOFPort, node);
+
+ if (!local) {
+ removeRemoteEgressTunnelBridgeRules(node, dpid, segmentationId, attachedMac, tunnelOFPort, localPort);
+ }
+ if (local && isLastInstanceOnNode) {
+ removePerTunnelRules(node, dpid, segmentationId, tunnelOFPort);
+ }
return;
}
}
}
@Override
- public Status handleInterfaceDelete(String tunnelType, String tunnelKey, Node source, Interface intf,
+ public Status handleInterfaceDelete(String tunnelType, String tunnelKey, Node srcNode, Interface intf,
boolean isLastInstanceOnNode) {
- // TODO Auto-generated method stub
- return null;
+ Status status = new Status(StatusCode.SUCCESS);
+ IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
+ List<Node> nodes = connectionService.getNodes();
+ nodes.remove(srcNode);
+
+ logger.info("Delete intf " + intf.getName() + " isLastInstanceOnNode " + isLastInstanceOnNode);
+ if (intf.getType().equalsIgnoreCase("vxlan") || intf.getType().equalsIgnoreCase("gre")) {
+ /* Delete tunnel port */
+ try {
+ OvsDBMap<String, String> options = intf.getOptions();
+ InetAddress src = InetAddress.getByName(options.get("local_ip"));
+ InetAddress dst = InetAddress.getByName(options.get("remote_ip"));
+ status = deleteTunnelPort(srcNode, intf.getType(), src, dst);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ } else {
+ /* delete all other interfaces */
+ this.removeLocalRules(tunnelType, tunnelKey,
+ srcNode, intf);
+
+ if (tunnelType.equalsIgnoreCase("gre")
+ || tunnelType.equalsIgnoreCase("vxlan")) {
+ for (Node dstNode : nodes) {
+ InetAddress src = AdminConfigManager.getManager().getTunnelEndPoint(srcNode);
+ InetAddress dst = AdminConfigManager.getManager().getTunnelEndPoint(dstNode);
+ logger.info("Remove tunnel rules for interface " + intf.getName() + " on srcNode" + srcNode.getNodeIDString());
+ this.removeTunnelRules(tunnelType, tunnelKey,
+ dst, srcNode, intf, true, isLastInstanceOnNode);
+ logger.info("Remove tunnel rules for interface " + intf.getName() + " on dstNode" + dstNode.getNodeIDString());
+ this.removeTunnelRules(tunnelType, tunnelKey,
+ src, dstNode, intf, false, isLastInstanceOnNode);
+ }
+ }
+ }
+ return status;
}
@Override
* table=0,tun_id=0x5,in_port=10, actions=goto_table:2
*/
- private void writeTunnelIn(Long dpidLong, Short writeTable, Short goToTableId, String segmentationId, Long ofPort) {
+ private void handleTunnelIn(Long dpidLong, Short writeTable, Short goToTableId,
+ String segmentationId, Long ofPort, boolean write) {
String nodeName = "openflow:" + dpidLong;
flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, tunnelId).build());
flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, ofPort).build());
- // Create the OF Actions and Instructions
- InstructionBuilder ib = new InstructionBuilder();
- InstructionsBuilder isb = new InstructionsBuilder();
+ if (write) {
+ // Create the OF Actions and Instructions
+ InstructionBuilder ib = new InstructionBuilder();
+ InstructionsBuilder isb = new InstructionsBuilder();
- // Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = new ArrayList<Instruction>();
- // Call the InstructionBuilder Methods Containing Actions
- createGotoTableInstructions(ib, goToTableId);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
+ // Call the InstructionBuilder Methods Containing Actions
+ createGotoTableInstructions(ib, goToTableId);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+ }
String flowId = "TunnelIn_"+segmentationId+"_"+ofPort;
// Add Flow Attributes
flowBuilder.setFlowName(flowId);
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
- writeFlow(flowBuilder, nodeBuilder);
+
+ if (write) {
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
}
/*
* actions=set_field:5->tun_id,goto_table=1"
*/
- private void writeLocalInPort(Long dpidLong, Short writeTable, Short goToTableId, String segmentationId, Long inPort, String attachedMac) {
+ private void handleLocalInPort(Long dpidLong, Short writeTable, Short goToTableId,
+ String segmentationId, Long inPort, String attachedMac, boolean write) {
String nodeName = "openflow:" + dpidLong;
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
- // Instantiate the Builders for the OF Actions and Instructions
- InstructionBuilder ib = new InstructionBuilder();
- InstructionsBuilder isb = new InstructionsBuilder();
+ if (write) {
+ // Instantiate the Builders for the OF Actions and Instructions
+ InstructionBuilder ib = new InstructionBuilder();
+ InstructionsBuilder isb = new InstructionsBuilder();
- // Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = new ArrayList<Instruction>();
- // GOTO Instuctions Need to be added first to the List
- createGotoTableInstructions(ib, goToTableId);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
- // TODO Broken SetTunID
- createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
- ib.setOrder(1);
- ib.setKey(new InstructionKey(1));
- instructions.add(ib.build());
+ // GOTO Instuctions Need to be added first to the List
+ createGotoTableInstructions(ib, goToTableId);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
+ // TODO Broken SetTunID
+ createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
+ ib.setOrder(1);
+ ib.setKey(new InstructionKey(1));
+ instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
- writeFlow(flowBuilder, nodeBuilder);
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
}
/*
* table=0,priority=16384,in_port=1 actions=drop"
*/
- private void writeDropSrcIface(Long dpidLong, Long inPort) {
+ private void handleDropSrcIface(Long dpidLong, Long inPort, boolean write) {
String nodeName = "openflow:" + dpidLong;
// Create the OF Match using MatchBuilder
flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, inPort).build());
- // Instantiate the Builders for the OF Actions and Instructions
- InstructionBuilder ib = new InstructionBuilder();
- InstructionsBuilder isb = new InstructionsBuilder();
+ if (write) {
+ // Instantiate the Builders for the OF Actions and Instructions
+ InstructionBuilder ib = new InstructionBuilder();
+ InstructionsBuilder isb = new InstructionsBuilder();
- // Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = new ArrayList<Instruction>();
- // Call the InstructionBuilder Methods Containing Actions
- createDropInstructions(ib);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
+ // Call the InstructionBuilder Methods Containing Actions
+ createDropInstructions(ib);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+ }
String flowId = "DropFilter_"+inPort;
// Add Flow Attributes
flowBuilder.setPriority(8192);
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
- writeFlow(flowBuilder, nodeBuilder);
+ if (write) {
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
}
/*
* actions=output:10,goto_table:2"
*/
- private void writeTunnelOut(Long dpidLong, Short writeTable, Short goToTableId, String segmentationId , Long OFPortOut, String attachedMac) {
+ private void handleTunnelOut(Long dpidLong, Short writeTable, Short goToTableId, String segmentationId,
+ Long OFPortOut, String attachedMac, boolean write) {
String nodeName = "openflow:" + dpidLong;
flowBuilder.setFlowName(flowId);
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
- // Instantiate the Builders for the OF Actions and Instructions
- InstructionBuilder ib = new InstructionBuilder();
- InstructionsBuilder isb = new InstructionsBuilder();
- // Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ if (write) {
+ // Instantiate the Builders for the OF Actions and Instructions
+ InstructionBuilder ib = new InstructionBuilder();
+ InstructionsBuilder isb = new InstructionsBuilder();
- // GOTO Instuctions
- createGotoTableInstructions(ib, goToTableId);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
- // Set the Output Port/Iface
- createOutputPortInstructions(ib, dpidLong, OFPortOut);
- ib.setOrder(1);
- ib.setKey(new InstructionKey(1));
- instructions.add(ib.build());
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = new ArrayList<Instruction>();
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // GOTO Instuctions
+ createGotoTableInstructions(ib, goToTableId);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
+ // Set the Output Port/Iface
+ createOutputPortInstructions(ib, dpidLong, OFPortOut);
+ ib.setOrder(1);
+ ib.setKey(new InstructionKey(1));
+ instructions.add(ib.build());
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- writeFlow(flowBuilder, nodeBuilder);
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
}
/*
* actions=output:10,output:11,goto_table:2
*/
- private void writeTunnelFloodOut(Long dpidLong, Short writeTable, Short localTable, String segmentationId, Long OFPortOut) {
+ private void handleTunnelFloodOut(Long dpidLong, Short writeTable, Short localTable,
+ String segmentationId, Long OFPortOut, boolean write) {
String nodeName = "openflow:" + dpidLong;
existingInstructions = ins.getInstruction();
}
}
- // GOTO Instuction
- createGotoTableInstructions(ib, localTable);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
- // Set the Output Port/Iface
- createOutputPortInstructions(ib, dpidLong, OFPortOut, existingInstructions);
- ib.setOrder(1);
- ib.setKey(new InstructionKey(1));
- instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ if (write) {
+ // GOTO Instuction
+ createGotoTableInstructions(ib, localTable);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
+ // Set the Output Port/Iface
+ createOutputPortInstructions(ib, dpidLong, OFPortOut, existingInstructions);
+ ib.setOrder(1);
+ ib.setKey(new InstructionKey(1));
+ instructions.add(ib.build());
+
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
+
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ /* remove port from action list */
+ boolean flowRemove = removeOutputPortFromInstructions(ib, dpidLong,OFPortOut, existingInstructions);
+ if (flowRemove) {
+ /* if all port are removed, remove the flow too. */
+ removeFlow(flowBuilder, nodeBuilder);
+ } else {
+ /* Install instruction with new output port list*/
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- writeFlow(flowBuilder, nodeBuilder);
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+ }
+ }
}
/*
* table=2,priority=8192,tun_id=0x5 actions=drop
*/
- private void writeTunnelMiss(Long dpidLong, Short writeTable, Short goToTableId, String segmentationId) {
+ private void handleTunnelMiss(Long dpidLong, Short writeTable, Short goToTableId, String segmentationId, boolean write) {
String nodeName = "openflow:" + dpidLong;
// Create Match(es) and Set them in the FlowBuilder Object
flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
- // Create the OF Actions and Instructions
- InstructionBuilder ib = new InstructionBuilder();
- InstructionsBuilder isb = new InstructionsBuilder();
+ if (write) {
+ // Create the OF Actions and Instructions
+ InstructionBuilder ib = new InstructionBuilder();
+ InstructionsBuilder isb = new InstructionsBuilder();
- // Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = new ArrayList<Instruction>();
- // Call the InstructionBuilder Methods Containing Actions
- createGotoTableInstructions(ib, goToTableId);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
+ // Call the InstructionBuilder Methods Containing Actions
+ createGotoTableInstructions(ib, goToTableId);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+ }
String flowId = "TunnelMiss_"+segmentationId;
// Add Flow Attributes
flowBuilder.setFlowName(flowId);
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
- writeFlow(flowBuilder, nodeBuilder);
+ if (write) {
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
}
/*
* table=2,tun_id=0x5,dl_dst=00:00:00:00:00:01 actions=output:2
*/
- private void writeLocalUcastOut(Long dpidLong, Short writeTable, String segmentationId, Long localPort, String attachedMac) {
+ private void handleLocalUcastOut(Long dpidLong, Short writeTable, String segmentationId, Long localPort,
+ String attachedMac, boolean write) {
String nodeName = "openflow:" + dpidLong;
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
- // Instantiate the Builders for the OF Actions and Instructions
- InstructionBuilder ib = new InstructionBuilder();
- InstructionsBuilder isb = new InstructionsBuilder();
+ if (write) {
+ // Instantiate the Builders for the OF Actions and Instructions
+ InstructionBuilder ib = new InstructionBuilder();
+ InstructionsBuilder isb = new InstructionsBuilder();
- // Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = new ArrayList<Instruction>();
- // Set the Output Port/Iface
- createOutputPortInstructions(ib, dpidLong, localPort);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
+ // Set the Output Port/Iface
+ createOutputPortInstructions(ib, dpidLong, localPort);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
- writeFlow(flowBuilder, nodeBuilder);
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
}
/*
* actions=output:2,3,4,5
*/
- private void writeLocalBcastOut(Long dpidLong, Short writeTable, String segmentationId, Long localPort) {
+ private void handleLocalBcastOut(Long dpidLong, Short writeTable, String segmentationId,
+ Long localPort, boolean write) {
String nodeName = "openflow:" + dpidLong;
}
}
- // Broken OutPort TODO: localPort needs to be a list of Ports)
- createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
+ if (write) {
+ // Create output port list
+ createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
- writeFlow(flowBuilder, nodeBuilder);
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ boolean flowRemove = removeOutputPortFromInstructions(ib, dpidLong,
+ localPort, existingInstructions);
+ if (flowRemove) {
+ /* if all ports are removed, remove flow */
+ removeFlow(flowBuilder, nodeBuilder);
+ } else {
+ /* Install instruction with new output port list*/
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
+
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
+
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+
+ writeFlow(flowBuilder, nodeBuilder);
+ }
+ }
}
/*
* table=2,priority=8192,tun_id=0x5 actions=drop
*/
- private void writeLocalTableMiss(Long dpidLong, Short writeTable, String segmentationId) {
+ private void handleLocalTableMiss(Long dpidLong, Short writeTable, String segmentationId,
+ boolean write) {
String nodeName = "openflow:" + dpidLong;
// Create Match(es) and Set them in the FlowBuilder Object
flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
- // Create the OF Actions and Instructions
- InstructionBuilder ib = new InstructionBuilder();
- InstructionsBuilder isb = new InstructionsBuilder();
+ if (write) {
+ // Create the OF Actions and Instructions
+ InstructionBuilder ib = new InstructionBuilder();
+ InstructionsBuilder isb = new InstructionsBuilder();
- // Instructions List Stores Individual Instructions
- List<Instruction> instructions = new ArrayList<Instruction>();
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = new ArrayList<Instruction>();
- // Call the InstructionBuilder Methods Containing Actions
- createDropInstructions(ib);
- ib.setOrder(0);
- ib.setKey(new InstructionKey(0));
- instructions.add(ib.build());
+ // Call the InstructionBuilder Methods Containing Actions
+ createDropInstructions(ib);
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
- // Add InstructionBuilder to the Instruction(s)Builder List
- isb.setInstruction(instructions);
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
- // Add InstructionsBuilder to FlowBuilder
- flowBuilder.setInstructions(isb.build());
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+ }
String flowId = "LocalTableMiss_"+segmentationId;
// Add Flow Attributes
flowBuilder.setFlowName(flowId);
flowBuilder.setHardTimeout(0);
flowBuilder.setIdleTimeout(0);
- writeFlow(flowBuilder, nodeBuilder);
+ if (write) {
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
}
private Flow getFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
}
}
+ private void removeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
+ IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+ if (mdsalConsumer == null) {
+ logger.error("ERROR finding MDSAL Service.");
+ return;
+ }
+
+ dataBrokerService = mdsalConsumer.getDataBrokerService();
+
+ if (dataBrokerService == null) {
+ logger.error("ERROR finding reference for DataBrokerService. Please check out the MD-SALsupport on the Controller.");
+ return;
+ }
+ DataModification<InstanceIdentifier<?>, DataObject> modification = dataBrokerService.beginTransaction();
+ InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class)
+ .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
+ .rev130819.nodes.Node.class, nodeBuilder.getKey())
+ .augmentation(FlowCapableNode.class).child(Table.class,
+ new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
+ //modification.removeOperationalData(nodeBuilderToInstanceId(nodeBuilder));
+ modification.removeOperationalData(path1);
+ //modification.removeConfigurationData(nodeBuilderToInstanceId(nodeBuilder));
+ modification.removeConfigurationData(path1);
+ Future<RpcResult<TransactionStatus>> commitFuture = modification.commit();
+ try {
+ RpcResult<TransactionStatus> result = commitFuture.get();
+ TransactionStatus status = result.getResult();
+ logger.debug("Transaction Status "+status.toString()+" for Flow "+flowBuilder.getFlowName());
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ } catch (ExecutionException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
/**
* Create Ingress Port Match dpidLong, inPort
*
return ib;
}
+ /**
+ * Remove Output Port from Instruction
+ *
+ * @param ib Map InstructionBuilder without any instructions
+ * @param dpidLong Long the datapath ID of a switch/node
+ * @param port Long representing a port on a switch/node
+ * @return ib InstructionBuilder Map with instructions
+ */
+ protected static boolean removeOutputPortFromInstructions(InstructionBuilder ib,
+ Long dpidLong, Long port , List<Instruction> instructions) {
+
+ NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+ logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
+
+ List<Action> actionList = new ArrayList<Action>();
+ ActionBuilder ab = new ActionBuilder();
+
+ List<Action> existingActions = null;
+ if (instructions != null) {
+ for (Instruction in : instructions) {
+ if (in.getInstruction() instanceof ApplyActionsCase) {
+ existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
+ actionList.addAll(existingActions);
+ break;
+ }
+ }
+ }
+
+ int numOutputPort = 0;
+ for (Action action : actionList) {
+ if (action.getAction() instanceof OutputActionCase) {
+ numOutputPort++;
+ OutputActionCase opAction = (OutputActionCase)action.getAction();
+ if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
+ /* Find the output port in action list and remove */
+ actionList.remove(action);
+ numOutputPort--;
+ break;
+ }
+ }
+ }
+
+ /* Put new action list in Apply Action instruction */
+ if (numOutputPort > 0) {
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+ return false;
+ } else {
+ /* if all output port are removed. Return true to indicate flow remove */
+ return true;
+ }
+ }
+
/**
* Create Set Vlan ID Instruction
*