@Override
    public void write(ChannelBuffer bb, OFBsnPduTxRequestVer10 message) {
      int startIndex = bb.writerIndex();
      // fixed value property version = 1
      bb.writeByte((byte) 0x1);
      // fixed value property type = 4
      bb.writeByte((byte) 0x4);
      // length is length of variable message, will be updated at the end
      int lengthIndex = bb.writerIndex();
      bb.writeShort(U16.t(0));

      bb.writeInt(U32.t(message.xid));
      // fixed value property experimenter = 0x5c16c7L
      bb.writeInt(0x5c16c7);
      // fixed value property subtype = 0x1fL
      bb.writeInt(0x1f);
      bb.writeInt(U32.t(message.txIntervalMs));
      message.portNo.write2Bytes(bb);
      bb.writeByte(U8.t(message.slotNum));
      // pad: 3 bytes
      bb.writeZero(3);
      bb.writeBytes(message.data);

      // update length field
      int length = bb.writerIndex() - startIndex;
      bb.setShort(lengthIndex, length);
    }
 @Override
 public void write(ChannelBuffer bb, OFBsnTlvIcmpTypeVer14 message) {
   // fixed value property type = 0x44
   bb.writeShort((short) 0x44);
   // fixed value property length = 5
   bb.writeShort((short) 0x5);
   bb.writeByte(U8.t(message.value));
 }
 @Override
 public void write(ByteBuf bb, OFBsnSetMirroringVer14 message) {
   // fixed value property version = 5
   bb.writeByte((byte) 0x5);
   // fixed value property type = 4
   bb.writeByte((byte) 0x4);
   // fixed value property length = 20
   bb.writeShort((short) 0x14);
   bb.writeInt(U32.t(message.xid));
   // fixed value property experimenter = 0x5c16c7L
   bb.writeInt(0x5c16c7);
   // fixed value property subtype = 0x3L
   bb.writeInt(0x3);
   bb.writeByte(U8.t(message.reportMirrorPorts));
   // pad: 3 bytes
   bb.writeZero(3);
 }
    @Override
    public OFBsnPduTxRequest readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 1
      byte version = bb.readByte();
      if (version != (byte) 0x1)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_10(1), got=" + version);
      // fixed value property type == 4
      byte type = bb.readByte();
      if (type != (byte) 0x4)
        throw new OFParseError("Wrong type: Expected=OFType.EXPERIMENTER(4), got=" + type);
      int length = U16.f(bb.readShort());
      if (length < MINIMUM_LENGTH)
        throw new OFParseError(
            "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property experimenter == 0x5c16c7L
      int experimenter = bb.readInt();
      if (experimenter != 0x5c16c7)
        throw new OFParseError(
            "Wrong experimenter: Expected=0x5c16c7L(0x5c16c7L), got=" + experimenter);
      // fixed value property subtype == 0x1fL
      int subtype = bb.readInt();
      if (subtype != 0x1f)
        throw new OFParseError("Wrong subtype: Expected=0x1fL(0x1fL), got=" + subtype);
      long txIntervalMs = U32.f(bb.readInt());
      OFPort portNo = OFPort.read2Bytes(bb);
      short slotNum = U8.f(bb.readByte());
      // pad: 3 bytes
      bb.skipBytes(3);
      byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start));

      OFBsnPduTxRequestVer10 bsnPduTxRequestVer10 =
          new OFBsnPduTxRequestVer10(xid, txIntervalMs, portNo, slotNum, data);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", bsnPduTxRequestVer10);
      return bsnPduTxRequestVer10;
    }
    @Override
    public OFBsnTlvIcmpType readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property type == 0x44
      short type = bb.readShort();
      if (type != (short) 0x44)
        throw new OFParseError("Wrong type: Expected=0x44(0x44), got=" + type);
      int length = U16.f(bb.readShort());
      if (length != 5) throw new OFParseError("Wrong length: Expected=5(5), got=" + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      short value = U8.f(bb.readByte());

      OFBsnTlvIcmpTypeVer14 bsnTlvIcmpTypeVer14 = new OFBsnTlvIcmpTypeVer14(value);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", bsnTlvIcmpTypeVer14);
      return bsnTlvIcmpTypeVer14;
    }
    @Override
    public OFBsnSetMirroring readFrom(ByteBuf bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 5
      byte version = bb.readByte();
      if (version != (byte) 0x5)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_14(5), got=" + version);
      // fixed value property type == 4
      byte type = bb.readByte();
      if (type != (byte) 0x4)
        throw new OFParseError("Wrong type: Expected=OFType.EXPERIMENTER(4), got=" + type);
      int length = U16.f(bb.readShort());
      if (length != 20) throw new OFParseError("Wrong length: Expected=20(20), got=" + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property experimenter == 0x5c16c7L
      int experimenter = bb.readInt();
      if (experimenter != 0x5c16c7)
        throw new OFParseError(
            "Wrong experimenter: Expected=0x5c16c7L(0x5c16c7L), got=" + experimenter);
      // fixed value property subtype == 0x3L
      int subtype = bb.readInt();
      if (subtype != 0x3)
        throw new OFParseError("Wrong subtype: Expected=0x3L(0x3L), got=" + subtype);
      short reportMirrorPorts = U8.f(bb.readByte());
      // pad: 3 bytes
      bb.skipBytes(3);

      OFBsnSetMirroringVer14 bsnSetMirroringVer14 =
          new OFBsnSetMirroringVer14(xid, reportMirrorPorts);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", bsnSetMirroringVer14);
      return bsnSetMirroringVer14;
    }
Ejemplo n.º 7
0
@SuppressWarnings("unchecked")
public class MatchField<F extends OFValueType<F>> {
  private final String name;
  public final MatchFields id;
  private final Prerequisite<?>[] prerequisites;

  private MatchField(final String name, final MatchFields id, Prerequisite<?>... prerequisites) {
    this.name = name;
    this.id = id;
    this.prerequisites = prerequisites;
  }

  public static final MatchField<OFPort> IN_PORT =
      new MatchField<OFPort>("in_port", MatchFields.IN_PORT);

  public static final MatchField<OFPort> IN_PHY_PORT =
      new MatchField<OFPort>(
          "in_phy_port", MatchFields.IN_PHY_PORT, new Prerequisite<OFPort>(MatchField.IN_PORT));

  public static final MatchField<OFMetadata> METADATA =
      new MatchField<OFMetadata>("metadata", MatchFields.METADATA);

  public static final MatchField<MacAddress> ETH_DST =
      new MatchField<MacAddress>("eth_dst", MatchFields.ETH_DST);

  public static final MatchField<MacAddress> ETH_SRC =
      new MatchField<MacAddress>("eth_src", MatchFields.ETH_SRC);

  public static final MatchField<EthType> ETH_TYPE =
      new MatchField<EthType>("eth_type", MatchFields.ETH_TYPE);

  public static final MatchField<VlanVid> VLAN_VID =
      new MatchField<VlanVid>("vlan_vid", MatchFields.VLAN_VID);

  public static final MatchField<VlanPcp> VLAN_PCP =
      new MatchField<VlanPcp>(
          "vlan_pcp", MatchFields.VLAN_PCP, new Prerequisite<VlanVid>(MatchField.VLAN_VID));

  public static final MatchField<IpDscp> IP_DSCP =
      new MatchField<IpDscp>(
          "ip_dscp",
          MatchFields.IP_DSCP,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));

  public static final MatchField<IpEcn> IP_ECN =
      new MatchField<IpEcn>(
          "ip_dscp",
          MatchFields.IP_ECN,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));

  public static final MatchField<IpProtocol> IP_PROTO =
      new MatchField<IpProtocol>(
          "ip_proto",
          MatchFields.IP_PROTO,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4, EthType.IPv6));

  public static final MatchField<IPv4Address> IPV4_SRC =
      new MatchField<IPv4Address>(
          "ipv4_src",
          MatchFields.IPV4_SRC,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4));

  public static final MatchField<IPv4Address> IPV4_DST =
      new MatchField<IPv4Address>(
          "ipv4_dst",
          MatchFields.IPV4_DST,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv4));

  public static final MatchField<TransportPort> TCP_SRC =
      new MatchField<TransportPort>(
          "tcp_src",
          MatchFields.TCP_SRC,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP));

  public static final MatchField<TransportPort> TCP_DST =
      new MatchField<TransportPort>(
          "tcp_dst",
          MatchFields.TCP_DST,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_TCP));

  public static final MatchField<TransportPort> UDP_SRC =
      new MatchField<TransportPort>(
          "udp_src",
          MatchFields.UDP_SRC,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP));

  public static final MatchField<TransportPort> UDP_DST =
      new MatchField<TransportPort>(
          "udp_dst",
          MatchFields.UDP_DST,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_UDP));

  public static final MatchField<TransportPort> SCTP_SRC =
      new MatchField<TransportPort>(
          "sctp_src",
          MatchFields.SCTP_SRC,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP));

  public static final MatchField<TransportPort> SCTP_DST =
      new MatchField<TransportPort>(
          "sctp_dst",
          MatchFields.SCTP_DST,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_SCTP));

  public static final MatchField<ICMPv4Type> ICMPV4_TYPE =
      new MatchField<ICMPv4Type>(
          "icmpv4_src",
          MatchFields.ICMPV4_TYPE,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP));

  public static final MatchField<ICMPv4Code> ICMPV4_CODE =
      new MatchField<ICMPv4Code>(
          "icmpv4_dst",
          MatchFields.ICMPV4_CODE,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_ICMP));

  public static final MatchField<ArpOpcode> ARP_OP =
      new MatchField<ArpOpcode>(
          "arp_op",
          MatchFields.ARP_OP,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));

  public static final MatchField<IPv4Address> ARP_SPA =
      new MatchField<IPv4Address>(
          "arp_spa",
          MatchFields.ARP_SPA,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));

  public static final MatchField<IPv4Address> ARP_TPA =
      new MatchField<IPv4Address>(
          "arp_tpa",
          MatchFields.ARP_TPA,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));

  public static final MatchField<MacAddress> ARP_SHA =
      new MatchField<MacAddress>(
          "arp_sha",
          MatchFields.ARP_SHA,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));

  public static final MatchField<MacAddress> ARP_THA =
      new MatchField<MacAddress>(
          "arp_tha",
          MatchFields.ARP_THA,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.ARP));

  public static final MatchField<IPv6Address> IPV6_SRC =
      new MatchField<IPv6Address>(
          "ipv6_src",
          MatchFields.IPV6_SRC,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));

  public static final MatchField<IPv6Address> IPV6_DST =
      new MatchField<IPv6Address>(
          "ipv6_dst",
          MatchFields.IPV6_DST,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));

  public static final MatchField<IPv6FlowLabel> IPV6_FLABEL =
      new MatchField<IPv6FlowLabel>(
          "ipv6_flabel",
          MatchFields.IPV6_FLABEL,
          new Prerequisite<EthType>(MatchField.ETH_TYPE, EthType.IPv6));

  public static final MatchField<U8> ICMPV6_TYPE =
      new MatchField<U8>(
          "icmpv6_type",
          MatchFields.ICMPV6_TYPE,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_IPv6_ICMP));

  public static final MatchField<U8> ICMPV6_CODE =
      new MatchField<U8>(
          "icmpv6_code",
          MatchFields.ICMPV6_CODE,
          new Prerequisite<IpProtocol>(MatchField.IP_PROTO, IpProtocol.IP_PROTO_IPv6_ICMP));

  public static final MatchField<IPv6Address> IPV6_ND_TARGET =
      new MatchField<IPv6Address>(
          "ipv6_nd_target",
          MatchFields.IPV6_ND_TARGET,
          new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short) 135), U8.of((short) 136)));

  public static final MatchField<MacAddress> IPV6_ND_SLL =
      new MatchField<MacAddress>(
          "ipv6_nd_sll",
          MatchFields.IPV6_ND_SLL,
          new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short) 135)));

  public static final MatchField<MacAddress> IPV6_ND_TLL =
      new MatchField<MacAddress>(
          "ipv6_nd_tll",
          MatchFields.IPV6_ND_TLL,
          new Prerequisite<U8>(MatchField.ICMPV6_TYPE, U8.of((short) 136)));

  public static final MatchField<U32> MPLS_LABEL =
      new MatchField<U32>(
          "mpls_label",
          MatchFields.MPLS_LABEL,
          new Prerequisite<EthType>(
              MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));

  public static final MatchField<U8> MPLS_TC =
      new MatchField<U8>(
          "mpls_tc",
          MatchFields.MPLS_TC,
          new Prerequisite<EthType>(
              MatchField.ETH_TYPE, EthType.MPLS_UNICAST, EthType.MPLS_MULTICAST));

  public String getName() {
    return name;
  }

  public boolean arePrerequisitesOK(Match match) {
    for (Prerequisite<?> p : this.prerequisites) {
      if (!p.isSatisfied(match)) {
        return false;
      }
    }
    return true;
  }
}