blob: 4bbd399a1160e480fb858db1afeb2b4bc50db9b1 [file] [log] [blame]
Pavlin Radoslavov204b2862013-07-12 14:15:36 -07001package net.onrc.onos.ofcontroller.util;
2
3import org.codehaus.jackson.annotate.JsonProperty;
4
5/**
6 * The class representing the Flow Path flags.
7 */
8public class FlowPathFlags {
9 private long flags;
10
11 // Discard the first-hop Flow Entry
Yuta HIGUCHI3238e8f2013-10-14 15:59:40 -070012 private static final long DISCARD_FIRST_HOP_ENTRY = (1 << 0);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070013
14 // Keep only the first-hop Flow Entry
Yuta HIGUCHI3238e8f2013-10-14 15:59:40 -070015 private static final long KEEP_ONLY_FIRST_HOP_ENTRY = (1 << 1);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070016
17 /**
18 * Default constructor.
19 */
20 public FlowPathFlags() {
21 this.flags = 0;
22 }
23
24 /**
25 * Constructor for given flags.
26 *
27 * @param flags the flags value to set.
28 */
29 public FlowPathFlags(long flags) {
30 this.flags = flags;
31 }
32
33 /**
34 * Constructor for given flags as a string.
35 *
36 * The string value should contain the name of each flags to set. E.g.:
37 * "DISCARD_FIRST_HOP_ENTRY,KEEP_ONLY_FIRST_HOP_ENTRY"
38 * @param flagsStr the string value of the flags to set.
39 */
40 public FlowPathFlags(String flagsStr) {
41 this.setFlagsStr(flagsStr);
42 }
43
44 /**
45 * Get the flags.
46 *
47 * @return the flags.
48 */
49 @JsonProperty("flags")
50 public long flags() { return flags; }
51
52 /**
53 * Set the flags.
54 *
55 * @param flags the flags value to set.
56 */
57 @JsonProperty("flags")
58 public void setFlags(long flags) {
59 this.flags = flags;
60 }
61
62 /**
63 * Set the flags as a string.
64 *
65 * The string value should contain the name of each flags to set. E.g.:
66 * "DISCARD_FIRST_HOP_ENTRY,KEEP_ONLY_FIRST_HOP_ENTRY"
67 * @param flagsStr the string value of the flags to set.
68 */
69 @JsonProperty("flagsStr")
70 public void setFlagsStr(String flagsStr) {
71 this.flags = 0L;
72
73 // Test all flags
74 if (flagsStr.contains("DISCARD_FIRST_HOP_ENTRY"))
75 this.flags |= DISCARD_FIRST_HOP_ENTRY;
76 if (flagsStr.contains("KEEP_ONLY_FIRST_HOP_ENTRY"))
77 this.flags |= KEEP_ONLY_FIRST_HOP_ENTRY;
78 }
79
80 /**
81 * Test whether the DISCARD_FIRST_HOP_ENTRY flag is set.
82 *
83 * @return true if the DISCARD_FIRST_HOP_ENTRY flag is set,
84 * otherwise false.
85 */
86 public boolean isDiscardFirstHopEntry() {
87 return ((flags & DISCARD_FIRST_HOP_ENTRY) != 0);
88 }
89
90 /**
91 * Test whether the KEEP_ONLY_FIRST_HOP_ENTRY flag is set.
92 *
93 * @return true if the KEEP_ONLY_FIRST_HOP_ENTRY flag is set,
94 * otherwise false.
95 */
96 public boolean isKeepOnlyFirstHopEntry() {
97 return ((flags & KEEP_ONLY_FIRST_HOP_ENTRY) != 0);
98 }
99
100 /**
101 * Convert the Flow Path Flags to a string.
102 *
103 * The string has the following form:
104 * [flags=DISCARD_FIRST_HOP_ENTRY,KEEP_ONLY_FIRST_HOP_ENTRY]
105 *
106 * @return the Flow Path flags as a string.
107 */
108 @Override
109 public String toString() {
110 String flagsStr = null;
111 String ret = "[flags=";
112
113 // Test all flags
114 if ((this.flags & DISCARD_FIRST_HOP_ENTRY) != 0) {
115 if (flagsStr != null)
116 flagsStr += ",";
117 flagsStr += "DISCARD_FIRST_HOP_ENTRY";
118 }
119 if ((this.flags & KEEP_ONLY_FIRST_HOP_ENTRY) != 0) {
120 if (flagsStr != null)
121 flagsStr += ",";
122 flagsStr += "KEEP_ONLY_FIRST_HOP_ENTRY";
123 }
124 ret += "]";
125
126 return ret;
127 }
128}