Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.util; |
| 2 | |
| 3 | import org.codehaus.jackson.annotate.JsonProperty; |
| 4 | |
| 5 | /** |
| 6 | * The class representing the Flow Path flags. |
| 7 | */ |
| 8 | public class FlowPathFlags { |
| 9 | private long flags; |
| 10 | |
| 11 | // Discard the first-hop Flow Entry |
Yuta HIGUCHI | 3238e8f | 2013-10-14 15:59:40 -0700 | [diff] [blame] | 12 | private static final long DISCARD_FIRST_HOP_ENTRY = (1 << 0); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 13 | |
| 14 | // Keep only the first-hop Flow Entry |
Yuta HIGUCHI | 3238e8f | 2013-10-14 15:59:40 -0700 | [diff] [blame] | 15 | private static final long KEEP_ONLY_FIRST_HOP_ENTRY = (1 << 1); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 16 | |
| 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 | */ |
Pavlin Radoslavov | 426d516 | 2013-12-11 12:46:58 -0800 | [diff] [blame] | 108 | @Override |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 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) { |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 115 | flagsStr += "DISCARD_FIRST_HOP_ENTRY"; |
| 116 | } |
| 117 | if ((this.flags & KEEP_ONLY_FIRST_HOP_ENTRY) != 0) { |
| 118 | if (flagsStr != null) |
| 119 | flagsStr += ","; |
| 120 | flagsStr += "KEEP_ONLY_FIRST_HOP_ENTRY"; |
| 121 | } |
Pavlin Radoslavov | 0f6ad7a | 2013-12-11 17:05:40 -0800 | [diff] [blame] | 122 | if (flagsStr != null) |
| 123 | ret += flagsStr; |
| 124 | ret += "]"; |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 125 | |
| 126 | return ret; |
| 127 | } |
| 128 | } |