Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 1 | package org.openflow.types; |
| 2 | |
| 3 | import org.jboss.netty.buffer.ChannelBuffer; |
| 4 | |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 5 | public class OFMetadata implements OFValueType<OFMetadata> { |
| 6 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 7 | private static int LENGTH = 8; |
| 8 | |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 9 | private final U64 u64; |
Yotam Harchol | c281360 | 2013-08-20 12:14:22 -0700 | [diff] [blame] | 10 | |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 11 | public static final OFMetadata NO_MASK = OFMetadata.of(U64.ofRaw(0xFFFFFFFFFFFFFFFFl)); |
| 12 | public static final OFMetadata FULL_MASK = OFMetadata.of(U64.ofRaw(0x0)); |
| 13 | |
| 14 | public OFMetadata(U64 ofRaw) { |
| 15 | u64 = ofRaw; |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 16 | } |
| 17 | |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 18 | public static OFMetadata of(U64 u64) { |
| 19 | return new OFMetadata(u64); |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 20 | } |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 21 | |
| 22 | public static OFMetadata ofRaw(long raw) { |
| 23 | return new OFMetadata(U64.ofRaw(raw)); |
| 24 | } |
| 25 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 26 | public static OFMetadata read8Bytes(ChannelBuffer cb) { |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 27 | return OFMetadata.ofRaw(cb.readLong()); |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 28 | } |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 29 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 30 | public void write8Bytes(ChannelBuffer cb) { |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 31 | u64.writeTo(cb); |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public int getLength() { |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 36 | return u64.getLength(); |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public OFMetadata applyMask(OFMetadata mask) { |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 41 | return OFMetadata.of(this.u64.applyMask(mask.u64)); |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 42 | } |
Andreas Wundsam | 880a2a8 | 2013-08-22 07:55:14 -0700 | [diff] [blame] | 43 | |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 44 | } |