/** * Set this OFMatch's parameters based on a comma-separated key=value pair dpctl-style string, * e.g., from the output of OFMatch.toString() <br> * * <p>Supported keys/values include <br> * * <p> * * <TABLE border=1> * <TR> * <TD>KEY(s) * <TD>VALUE * </TR> * <TR> * <TD>"in_port","input_port" * <TD>integer * </TR> * <TR> * <TD>"dl_src","eth_src", "dl_dst","eth_dst" * <TD>hex-string * </TR> * <TR> * <TD>"dl_type", "dl_vlan", "dl_vlan_pcp" * <TD>integer * </TR> * <TR> * <TD>"nw_src", "nw_dst", "ip_src", "ip_dst" * <TD>CIDR-style netmask * </TR> * <TR> * <TD>"tp_src","tp_dst" * <TD>integer (max 64k) * </TR> * </TABLE> * * <p>The CIDR-style netmasks assume 32 netmask if none given, so: "128.8.128.118/32" is the same * as "128.8.128.118" * * @param match a key=value comma separated string, e.g. * "in_port=5,ip_dst=192.168.0.0/16,tp_src=80" * @throws IllegalArgumentException on unexpected key or value */ public void fromString(String match) throws IllegalArgumentException { if (match.equals("") || match.equalsIgnoreCase("any") || match.equalsIgnoreCase("all") || match.equals("[]")) match = "OFMatch[]"; String[] tokens = match.split("[\\[,\\]]"); String[] values; int initArg = 0; if (tokens[0].equals("OFMatch")) initArg = 1; this.wildcards = OFPFW_ALL; int i; for (i = initArg; i < tokens.length; i++) { values = tokens[i].split("="); if (values.length != 2) throw new IllegalArgumentException( "Token " + tokens[i] + " does not have form 'key=value' parsing " + match); values[0] = values[0].toLowerCase(); // try to make this case insens if (values[0].equals(STR_IN_PORT) || values[0].equals("input_port")) { this.inputPort = U16.t(Integer.valueOf(values[1])); this.wildcards &= ~OFPFW_IN_PORT; } else if (values[0].equals(STR_DL_DST) || values[0].equals("eth_dst")) { this.dataLayerDestination = HexString.fromHexString(values[1]); this.wildcards &= ~OFPFW_DL_DST; } else if (values[0].equals(STR_DL_SRC) || values[0].equals("eth_src")) { this.dataLayerSource = HexString.fromHexString(values[1]); this.wildcards &= ~OFPFW_DL_SRC; } else if (values[0].equals(STR_DL_TYPE) || values[0].equals("eth_type")) { if (values[1].startsWith("0x")) this.dataLayerType = U16.t(Integer.valueOf(values[1].replaceFirst("0x", ""), 16)); else this.dataLayerType = U16.t(Integer.valueOf(values[1])); this.wildcards &= ~OFPFW_DL_TYPE; } else if (values[0].equals(STR_DL_VLAN)) { if (values[1].startsWith("0x")) this.dataLayerVirtualLan = U16.t(Integer.valueOf(values[1].replaceFirst("0x", ""), 16)); else this.dataLayerVirtualLan = U16.t(Integer.valueOf(values[1])); this.wildcards &= ~OFPFW_DL_VLAN; } else if (values[0].equals(STR_DL_VLAN_PCP)) { if (values[1].startsWith("0x")) this.dataLayerVirtualLanPriorityCodePoint = U8.t(Short.valueOf(values[1].replaceFirst("0x", ""), 16)); else this.dataLayerVirtualLanPriorityCodePoint = U8.t(Short.valueOf(values[1])); this.wildcards &= ~OFPFW_DL_VLAN_PCP; } else if (values[0].equals(STR_NW_DST) || values[0].equals("ip_dst")) setFromCIDR(values[1], STR_NW_DST); else if (values[0].equals(STR_NW_SRC) || values[0].equals("ip_src")) setFromCIDR(values[1], STR_NW_SRC); else if (values[0].equals(STR_NW_PROTO)) { this.networkProtocol = U8.t(Short.valueOf(values[1])); this.wildcards &= ~OFPFW_NW_PROTO; } else if (values[0].equals(STR_NW_TOS)) { this.networkTypeOfService = U8.t(Short.valueOf(values[1])); this.wildcards &= ~OFPFW_NW_TOS; } else if (values[0].equals(STR_TP_DST)) { this.transportDestination = U16.t(Integer.valueOf(values[1])); this.wildcards &= ~OFPFW_TP_DST; } else if (values[0].equals(STR_TP_SRC)) { this.transportSource = U16.t(Integer.valueOf(values[1])); this.wildcards &= ~OFPFW_TP_SRC; } else throw new IllegalArgumentException("unknown token " + tokens[i] + " parsing " + match); } }