Exemple #1
0
 /**
  * Returns a summary of the message
  *
  * @return "ofmsg=v=$version;t=$type:l=$len:xid=$xid"
  */
 public String toString() {
   return "snmpmsg"
       + ":v="
       + U8.f(this.getVersion())
       + ";t="
       + this.getType()
       + ";l="
       + this.getLengthU()
       + ";x="
       + U32.f(this.getXid());
 }
Exemple #2
0
  /**
   * Output a dpctl-styled string, i.e., only list the elements that are not wildcarded
   *
   * <p>A match-everything OFMatch outputs "OFMatch[]"
   *
   * @return "OFMatch[dl_src:00:20:01:11:22:33,nw_src:192.168.0.0/24,tp_dst:80]"
   */
  @Override
  public String toString() {

    String str = "";

    // l1
    if ((wildcards & OFPFW_IN_PORT) == 0) str += "," + STR_IN_PORT + "=" + U16.f(this.inputPort);

    // l2
    if ((wildcards & OFPFW_DL_DST) == 0)
      str += "," + STR_DL_DST + "=" + HexString.toHexString(this.dataLayerDestination);
    if ((wildcards & OFPFW_DL_SRC) == 0)
      str += "," + STR_DL_SRC + "=" + HexString.toHexString(this.dataLayerSource);
    if ((wildcards & OFPFW_DL_TYPE) == 0)
      str += "," + STR_DL_TYPE + "=0x" + Integer.toHexString(U16.f(this.dataLayerType));
    if ((wildcards & OFPFW_DL_VLAN) == 0)
      str += "," + STR_DL_VLAN + "=" + U16.f(this.dataLayerVirtualLan);
    if ((wildcards & OFPFW_DL_VLAN_PCP) == 0)
      str += "," + STR_DL_VLAN_PCP + "=" + U8.f(this.dataLayerVirtualLanPriorityCodePoint);

    // l3
    if (getNetworkDestinationMaskLen() > 0)
      str +=
          "," + STR_NW_DST + "=" + cidrToString(networkDestination, getNetworkDestinationMaskLen());
    if (getNetworkSourceMaskLen() > 0)
      str += "," + STR_NW_SRC + "=" + cidrToString(networkSource, getNetworkSourceMaskLen());
    if ((wildcards & OFPFW_NW_PROTO) == 0) str += "," + STR_NW_PROTO + "=" + this.networkProtocol;
    if ((wildcards & OFPFW_NW_TOS) == 0) str += "," + STR_NW_TOS + "=" + this.networkTypeOfService;

    // l4
    if ((wildcards & OFPFW_TP_DST) == 0) str += "," + STR_TP_DST + "=" + this.transportDestination;
    if ((wildcards & OFPFW_TP_SRC) == 0) str += "," + STR_TP_SRC + "=" + this.transportSource;
    if ((str.length() > 0) && (str.charAt(0) == ','))
      str = str.substring(1); // trim the leading ","
    // done
    return "OFMatch[" + str + "]";
  }
Exemple #3
0
 /**
  * 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);
   }
 }