2 * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowjava.eric.codec.match;
10 import com.google.common.primitives.Ints;
15 public class EricHeader {
17 private final long headerAsLong;
18 private final int oxmClass;
19 private final int ericField;
20 private final boolean hasMask;
21 private final int length;
23 public EricHeader(final long header) {
24 this.headerAsLong = header;
25 this.oxmClass = Ints.checkedCast(extractSub(header, 16, 16));
26 this.ericField = Ints.checkedCast(extractSub(header, 7, 9));
27 this.hasMask = extractSub(header, 1, 8) == 1;
28 this.length = Ints.checkedCast(extractSub(header, 8, 0));
31 public EricHeader(final int oxmClass, final int ericField, final boolean hasMask, final int length) {
32 this.oxmClass = oxmClass;
33 this.ericField = ericField;
34 this.hasMask = hasMask;
36 this.headerAsLong = (long) oxmClass << 16 | ericField << 9 | (hasMask ? 1 : 0) << 8 | length;
39 private static long extractSub(final long value, final int nrBits, final int offset) {
40 final long rightShifted = value >>> offset;
41 final long mask = (1L << nrBits) - 1L;
42 return rightShifted & mask;
45 public long toLong() {
49 public int getOxmClass() {
53 public int getEricField() {
57 public boolean isHasMask() {
61 public int getLength() {
66 public int hashCode() {
69 result = prime * result + (int) (headerAsLong ^ headerAsLong >>> 32);
74 public boolean equals(final Object obj) {
81 if (getClass() != obj.getClass()) {
84 EricHeader other = (EricHeader) obj;
85 if (headerAsLong != other.headerAsLong) {
92 public String toString() {
93 return "EricHeader [headerAsLong=" + headerAsLong + ", oxmClass=" + oxmClass + ", ericField=" + ericField
94 + ", hasMask=" + hasMask + ", length=" + length + "]";