Skip to content
Snippets Groups Projects
Commit 55c0108c authored by sanjivininaikar's avatar sanjivininaikar
Browse files

Update StaticFlowEntryPusherResource.java

IPv6 support updated
parent 114dc96c
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory;
import net.floodlightcontroller.core.annotations.LogMessageCategory;
import net.floodlightcontroller.core.annotations.LogMessageDoc;
import net.floodlightcontroller.staticflowentry.HeaderFieldsException;
import net.floodlightcontroller.staticflowentry.StaticFlowEntries;
import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher;
import net.floodlightcontroller.storage.IStorageSourceService;
......@@ -42,14 +41,168 @@ import net.floodlightcontroller.storage.IStorageSourceService;
public class StaticFlowEntryPusherResource extends ServerResource {
protected static Logger log = LoggerFactory.getLogger(StaticFlowEntryPusherResource.class);
/**
* Checks to see if the user matches IP information without
* checking for the correct ether-type (2048).
* @param rows The Map that is a string representation of
* the static flow.
* @reutrn True if they checked the ether-type, false otherwise
*/
private boolean checkMatchIp(Map<String, Object> rows) {
public static boolean ip6 = false;
public static boolean ip4 = false;
/**
* Validates if all the mandatory fields are set properly while adding an IPv6 flow
* @param Map containing the fields of the flow
* @return state indicating whether a flow is valid or not
*/
private int checkMatch(Map<String, Object> rows) {
//sanjivini
//Initializing flags
int state = 0;
boolean dl_type = false;
boolean nw_proto = false;
boolean nw_layer = false;
boolean icmp6_type = false;
boolean icmp6_code = false;
boolean nd_target = false;
boolean nd_sll = false;
boolean nd_tll = false;
String eth_type = null;
String nw_protocol = null;
int icmp_type = -1;
//Determine the dl_type if set
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_DL_TYPE)) {
dl_type = true;
eth_type = (String) rows.get(StaticFlowEntryPusher.COLUMN_DL_TYPE);
if (eth_type.equalsIgnoreCase("0x86dd") || eth_type.equals("34525")) {
ip6 = true;
}
else if (eth_type.equalsIgnoreCase("0x800") || eth_type.equals("2048")||
eth_type.equalsIgnoreCase("0x806") || eth_type.equals("2054")) {
ip4 = true;
}
else {
state = 2;
return state;
}
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_NW_DST) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_NW_SRC)) {
nw_layer = true;
ip4 = true;
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_ICMP_CODE) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_ICMP_TYPE) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_ARP_DHA) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_ARP_SHA) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_ARP_SPA) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_ARP_DPA) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_ARP_OPCODE)) {
ip4 = true;
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_IPV6_FLOW_LABEL) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_NW6_SRC) ||
rows.containsKey(StaticFlowEntryPusher.COLUMN_NW6_DST)
) {
nw_layer = true;
ip6 = true;
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_NW_PROTO)) {
nw_proto = true;
nw_protocol = (String) rows.get(StaticFlowEntryPusher.COLUMN_NW_PROTO);
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_ICMP6_CODE)) {
icmp6_code = true;
ip6 = true;
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_ICMP6_TYPE)) {
icmp6_type = true;
ip6 = true;
icmp_type = Integer.parseInt((String) rows.get(StaticFlowEntryPusher.COLUMN_ICMP6_TYPE));
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_ND_SLL)) {
nd_sll = true;
ip6 = true;
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_ND_TLL)) {
nd_tll = true;
ip6 = true;
}
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_ND_TARGET)) {
nd_target = true;
ip6 = true;
}
if (nw_layer == true || nw_proto == true) {
if (dl_type == true) {
if (ip4 == false || ip6 == false) {
//invalid dl_type
state = 2;
return state;
}
}
else {
//dl_type not set
state = 1;
return state;
}
}
if (icmp6_type == true || icmp6_code == true ) {
if (nw_proto == true) {
if (!(nw_protocol.equals("58") || nw_protocol.equalsIgnoreCase("0x3A"))) {
//invalid nw_proto
state = 4;
return state;
}
}
else {
//nw_proto not set
state = 3;
return state;
}
}
if (nd_sll == true || nd_tll == true || nd_target == true) {
if (icmp6_type == true) {
//icmp_type must be set to 135/136 to set ipv6_nd_target
if (nd_target == true) {
if (!(icmp_type == 135 || icmp_type == 136)) {
//invalid icmp6_type
state = 6;
return state;
}
}
//icmp_type must be set to 136 to set ipv6_nd_tll
else if (nd_tll == true) {
if (!(icmp_type == 136)) {
//invalid icmp6_type
state = 6;
return state;
}
}
//icmp_type must be set to 135 to set ipv6_nd_sll
else if (nd_sll == true) {
if (!(icmp_type == 135)) {
//invalid icmp6_type
state = 6;
return state;
}
}
}
else {
//icmp6_type not set
state = 5;
return state;
}
}
if (ip4 == true && ip6 == true) {
//ipv4 & ipv6 conflict
state = 7;
return state;
}
return state;
//sanjivini
/*
boolean matchEther = false;
String val = (String) rows.get(StaticFlowEntryPusher.COLUMN_DL_TYPE);
if (val != null) {
......@@ -60,9 +213,9 @@ public class StaticFlowEntryPusherResource extends ServerResource {
} else {
try {
type = Integer.parseInt(val);
} catch (NumberFormatException e) { /* fail silently */}
} catch (NumberFormatException e) { /* fail silently */ /*}
}
if ((type == 2048) || (type == 34525) ) matchEther = true;
if ((type == 2048)|| (type == 34525)) matchEther = true;
}
if ((rows.containsKey(StaticFlowEntryPusher.COLUMN_NW_DST) ||
......@@ -75,6 +228,7 @@ public class StaticFlowEntryPusherResource extends ServerResource {
return false;
return true;
*/
}
/**
......@@ -97,12 +251,30 @@ public class StaticFlowEntryPusherResource extends ServerResource {
try {
rowValues = StaticFlowEntries.jsonToStorageEntry(fmJson);
String status = null;
if (!checkMatchIp(rowValues)) {
status = "Warning! Pushing a static flow entry that matches IP " +
"fields without matching for IP payload (ether-type IPv4 or IPv6 ) will cause " +
"the switch to wildcard higher level fields.";
int state = checkMatch(rowValues);
if (state == 1) {
status = "Warning! Must specify eth_type of IPv4/IPv6 to " +
"match on IPv4/IPv6 fields! The flow has been discarded.";
log.error(status);
} else {
} else if (state == 2) {
status = "Warning! eth_type not recognized! The flow has been discarded.";
log.error(status);
} else if (state == 3) {
status = "Warning! Must specify ip_proto to match! The flow has been discarded.";
log.error(status);
} else if (state == 4) {
status = "Warning! ip_proto invalid! The flow has been discarded.";
log.error(status);
} else if (state == 5) {
status = "Warning! Must specify icmp6_type to match! The flow has been discarded.";
log.error(status);
} else if (state == 6) {
status = "Warning! icmp6_type invalid! The flow has been discarded.";
log.error(status);
} else if (state == 7) {
status = "Warning! IPv4 & IPv6 fields cannot be specified in the same flow! The flow has been discarded.";
log.error(status);
} else if (state == 0) {
status = "Entry pushed";
}
storageSource.insertRowAsync(StaticFlowEntryPusher.TABLE_NAME, rowValues);
......@@ -110,12 +282,12 @@ public class StaticFlowEntryPusherResource extends ServerResource {
} catch (IOException e) {
log.error("Error parsing push flow mod request: " + fmJson, e);
return "{\"status\" : \"Error! Could not parse flod mod, see log for details.\"}";
} catch (HeaderFieldsException e) {
}
catch (Exception e) {
log.error("Error parsing push flow mod request: " + fmJson, e);
return "{\"status\" : \"Error! Check the fields specified for the flow.Make sure IPv4 fields are not mixed with IPv6 fields or all "
+ "mandatory fields are specified.\"}";
}
}
@Delete
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment