Carmelo Cascone
Committed by Thomas Vachuska

Polished BMv2 protocol module

- Improved and fixed typos in javadocs
- Added missing beta API annotations
- Refactored the default interpreter implementation

Change-Id: Ibfb21d31415d8f25cc67307f8bea2871951c9a8f
Showing 29 changed files with 129 additions and 71 deletions
...@@ -18,6 +18,7 @@ package org.onosproject.bmv2.api.context; ...@@ -18,6 +18,7 @@ package org.onosproject.bmv2.api.context;
18 18
19 import com.eclipsesource.json.JsonArray; 19 import com.eclipsesource.json.JsonArray;
20 import com.eclipsesource.json.JsonObject; 20 import com.eclipsesource.json.JsonObject;
21 +import com.google.common.annotations.Beta;
21 import com.google.common.base.MoreObjects; 22 import com.google.common.base.MoreObjects;
22 import com.google.common.base.Objects; 23 import com.google.common.base.Objects;
23 import com.google.common.collect.ImmutableList; 24 import com.google.common.collect.ImmutableList;
...@@ -36,6 +37,7 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -36,6 +37,7 @@ import static com.google.common.base.Preconditions.checkArgument;
36 /** 37 /**
37 * Default implementation of a BMv2 configuration backed by a JSON object. 38 * Default implementation of a BMv2 configuration backed by a JSON object.
38 */ 39 */
40 +@Beta
39 public final class Bmv2DefaultConfiguration implements Bmv2Configuration { 41 public final class Bmv2DefaultConfiguration implements Bmv2Configuration {
40 42
41 private final JsonObject json; 43 private final JsonObject json;
......
...@@ -37,9 +37,9 @@ public interface Bmv2FlowRuleTranslator { ...@@ -37,9 +37,9 @@ public interface Bmv2FlowRuleTranslator {
37 * <li> action: is built using the context interpreter 37 * <li> action: is built using the context interpreter
38 * {@link Bmv2Interpreter#mapTreatment(org.onosproject.net.flow.TrafficTreatment, Bmv2Configuration) 38 * {@link Bmv2Interpreter#mapTreatment(org.onosproject.net.flow.TrafficTreatment, Bmv2Configuration)
39 * treatment mapping function} or the flow rule 39 * treatment mapping function} or the flow rule
40 - * {@link org.onosproject.bmv2.api.runtime.Bmv2ExtensionTreatment} extension treatment} (if any). 40 + * {@link org.onosproject.bmv2.api.runtime.Bmv2ExtensionTreatment extension treatment} (if any).
41 - * <li> timeout: if the table supports timeout, use the same as the flow rule, otherwise none (i.e. permanent 41 + * <li> timeout: if the table supports timeout, use the same as the flow rule, otherwise none (i.e. returns a
42 - * entry). 42 + * permanent entry).
43 * </ul> 43 * </ul>
44 * 44 *
45 * @param rule a flow rule 45 * @param rule a flow rule
......
...@@ -16,10 +16,13 @@ ...@@ -16,10 +16,13 @@
16 16
17 package org.onosproject.bmv2.api.context; 17 package org.onosproject.bmv2.api.context;
18 18
19 +import com.google.common.annotations.Beta;
20 +
19 /** 21 /**
20 * BMv2 flow rule translator exception. 22 * BMv2 flow rule translator exception.
21 */ 23 */
22 -public class Bmv2FlowRuleTranslatorException extends Exception { 24 +@Beta
25 +public final class Bmv2FlowRuleTranslatorException extends Exception {
23 26
24 public Bmv2FlowRuleTranslatorException(String msg) { 27 public Bmv2FlowRuleTranslatorException(String msg) {
25 super(msg); 28 super(msg);
......
...@@ -16,10 +16,13 @@ ...@@ -16,10 +16,13 @@
16 16
17 package org.onosproject.bmv2.api.context; 17 package org.onosproject.bmv2.api.context;
18 18
19 +import com.google.common.annotations.Beta;
20 +
19 /** 21 /**
20 * A BMv2 interpreter exception. 22 * A BMv2 interpreter exception.
21 */ 23 */
22 -public class Bmv2InterpreterException extends Exception { 24 +@Beta
25 +public final class Bmv2InterpreterException extends Exception {
23 26
24 public Bmv2InterpreterException(String message) { 27 public Bmv2InterpreterException(String message) {
25 super(message); 28 super(message);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.collect.Lists; 21 import com.google.common.collect.Lists;
21 import org.onlab.util.ImmutableByteSequence; 22 import org.onlab.util.ImmutableByteSequence;
...@@ -30,6 +31,7 @@ import static com.google.common.base.Preconditions.checkState; ...@@ -30,6 +31,7 @@ import static com.google.common.base.Preconditions.checkState;
30 /** 31 /**
31 * An action of a BMv2 match-action table entry. 32 * An action of a BMv2 match-action table entry.
32 */ 33 */
34 +@Beta
33 public final class Bmv2Action { 35 public final class Bmv2Action {
34 36
35 private final String name; 37 private final String name;
...@@ -58,8 +60,7 @@ public final class Bmv2Action { ...@@ -58,8 +60,7 @@ public final class Bmv2Action {
58 } 60 }
59 61
60 /** 62 /**
61 - * Returns an immutable view of the ordered list of parameters of this 63 + * Returns an immutable view of the list of parameters of this action.
62 - * action.
63 * 64 *
64 * @return list of byte sequence 65 * @return list of byte sequence
65 */ 66 */
...@@ -106,7 +107,7 @@ public final class Bmv2Action { ...@@ -106,7 +107,7 @@ public final class Bmv2Action {
106 } 107 }
107 108
108 /** 109 /**
109 - * Set the action name. 110 + * Sets the action name.
110 * 111 *
111 * @param actionName a string value 112 * @param actionName a string value
112 * @return this 113 * @return this
...@@ -117,7 +118,7 @@ public final class Bmv2Action { ...@@ -117,7 +118,7 @@ public final class Bmv2Action {
117 } 118 }
118 119
119 /** 120 /**
120 - * Add a parameter at the end of the parameters list. 121 + * Adds a parameter at the end of the parameters list.
121 * 122 *
122 * @param parameter a ByteBuffer value 123 * @param parameter a ByteBuffer value
123 * @return this 124 * @return this
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.Objects; 20 import com.google.common.base.Objects;
20 import org.onosproject.net.DeviceId; 21 import org.onosproject.net.DeviceId;
21 22
...@@ -27,8 +28,9 @@ import java.util.regex.Pattern; ...@@ -27,8 +28,9 @@ import java.util.regex.Pattern;
27 import static com.google.common.base.Preconditions.checkNotNull; 28 import static com.google.common.base.Preconditions.checkNotNull;
28 29
29 /** 30 /**
30 - * Representation of a BMv2 device. 31 + * A BMv2 device.
31 */ 32 */
33 +@Beta
32 public final class Bmv2Device { 34 public final class Bmv2Device {
33 35
34 public static final String N_A = "n/a"; 36 public static final String N_A = "n/a";
...@@ -47,9 +49,9 @@ public final class Bmv2Device { ...@@ -47,9 +49,9 @@ public final class Bmv2Device {
47 /** 49 /**
48 * Creates a new BMv2 device object. 50 * Creates a new BMv2 device object.
49 * 51 *
50 - * @param thriftServerHost the hostname / IP address of the Thrift runtime server running on the device 52 + * @param thriftServerHost the hostname or IP address of the Thrift RPC server running on the device
51 - * @param thriftServerPort the port of the Thrift runtime server running on the device 53 + * @param thriftServerPort the listening port used by the device Thrift RPC server
52 - * @param internalDeviceId the internal device ID number 54 + * @param internalDeviceId the internal numeric device ID
53 */ 55 */
54 public Bmv2Device(String thriftServerHost, int thriftServerPort, int internalDeviceId) { 56 public Bmv2Device(String thriftServerHost, int thriftServerPort, int internalDeviceId) {
55 this.thriftServerHost = checkNotNull(thriftServerHost, "host cannot be null"); 57 this.thriftServerHost = checkNotNull(thriftServerHost, "host cannot be null");
...@@ -68,7 +70,7 @@ public final class Bmv2Device { ...@@ -68,7 +70,7 @@ public final class Bmv2Device {
68 } 70 }
69 71
70 /** 72 /**
71 - * Returns the hostname (or IP address) of the Thrift runtime server running on the device. 73 + * Returns the hostname or IP address of the Thrift RPC server running on the device.
72 * 74 *
73 * @return a string value 75 * @return a string value
74 */ 76 */
...@@ -77,7 +79,7 @@ public final class Bmv2Device { ...@@ -77,7 +79,7 @@ public final class Bmv2Device {
77 } 79 }
78 80
79 /** 81 /**
80 - * Returns the port of the Thrift runtime server running on the device. 82 + * Returns the listening port of the Thrift RPC server running on the device.
81 * 83 *
82 * @return an integer value 84 * @return an integer value
83 */ 85 */
...@@ -102,7 +104,6 @@ public final class Bmv2Device { ...@@ -102,7 +104,6 @@ public final class Bmv2Device {
102 */ 104 */
103 public DeviceId asDeviceId() { 105 public DeviceId asDeviceId() {
104 try { 106 try {
105 - // TODO: include internalDeviceId number in the deviceId URI
106 return DeviceId.deviceId(new URI(SCHEME, this.thriftServerHost + ":" + this.thriftServerPort, 107 return DeviceId.deviceId(new URI(SCHEME, this.thriftServerHost + ":" + this.thriftServerPort,
107 String.valueOf(this.internalDeviceId))); 108 String.valueOf(this.internalDeviceId)));
108 } catch (URISyntaxException e) { 109 } catch (URISyntaxException e) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import org.apache.commons.lang3.tuple.Pair; 20 import org.apache.commons.lang3.tuple.Pair;
20 import org.onlab.util.ImmutableByteSequence; 21 import org.onlab.util.ImmutableByteSequence;
21 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
...@@ -26,6 +27,7 @@ import java.util.List; ...@@ -26,6 +27,7 @@ import java.util.List;
26 /** 27 /**
27 * An agent to control a BMv2 device. 28 * An agent to control a BMv2 device.
28 */ 29 */
30 +@Beta
29 public interface Bmv2DeviceAgent { 31 public interface Bmv2DeviceAgent {
30 32
31 /** 33 /**
...@@ -43,20 +45,20 @@ public interface Bmv2DeviceAgent { ...@@ -43,20 +45,20 @@ public interface Bmv2DeviceAgent {
43 boolean ping(); 45 boolean ping();
44 46
45 /** 47 /**
46 - * Adds a new table entry. 48 + * Adds a new table entry. If successful returns a table-specific identifier of the installed entry.
47 * 49 *
48 - * @param entry a table entry value 50 + * @param entry a table entry
49 - * @return table-specific entry ID 51 + * @return a long value
50 * @throws Bmv2RuntimeException if any error occurs 52 * @throws Bmv2RuntimeException if any error occurs
51 */ 53 */
52 long addTableEntry(Bmv2TableEntry entry) throws Bmv2RuntimeException; 54 long addTableEntry(Bmv2TableEntry entry) throws Bmv2RuntimeException;
53 55
54 /** 56 /**
55 - * Modifies an existing table entry by updating its action. 57 + * Modifies an existing entry at by updating its action.
56 * 58 *
57 - * @param tableName string value of table name 59 + * @param tableName a string value
58 - * @param entryId long value of entry ID 60 + * @param entryId a long value
59 - * @param action an action value 61 + * @param action an action
60 * @throws Bmv2RuntimeException if any error occurs 62 * @throws Bmv2RuntimeException if any error occurs
61 */ 63 */
62 void modifyTableEntry(String tableName, long entryId, Bmv2Action action) throws Bmv2RuntimeException; 64 void modifyTableEntry(String tableName, long entryId, Bmv2Action action) throws Bmv2RuntimeException;
...@@ -64,16 +66,16 @@ public interface Bmv2DeviceAgent { ...@@ -64,16 +66,16 @@ public interface Bmv2DeviceAgent {
64 /** 66 /**
65 * Deletes currently installed entry. 67 * Deletes currently installed entry.
66 * 68 *
67 - * @param tableName string value of table name 69 + * @param tableName a string value
68 - * @param entryId long value of entry ID 70 + * @param entryId a long value
69 * @throws Bmv2RuntimeException if any error occurs 71 * @throws Bmv2RuntimeException if any error occurs
70 */ 72 */
71 void deleteTableEntry(String tableName, long entryId) throws Bmv2RuntimeException; 73 void deleteTableEntry(String tableName, long entryId) throws Bmv2RuntimeException;
72 74
73 /** 75 /**
74 - * Sets table default action. 76 + * Sets a default action for the given table.
75 * 77 *
76 - * @param tableName string value of table name 78 + * @param tableName a string value
77 * @param action an action value 79 * @param action an action value
78 * @throws Bmv2RuntimeException if any error occurs 80 * @throws Bmv2RuntimeException if any error occurs
79 */ 81 */
...@@ -97,7 +99,7 @@ public interface Bmv2DeviceAgent { ...@@ -97,7 +99,7 @@ public interface Bmv2DeviceAgent {
97 List<Bmv2ParsedTableEntry> getTableEntries(String tableName) throws Bmv2RuntimeException; 99 List<Bmv2ParsedTableEntry> getTableEntries(String tableName) throws Bmv2RuntimeException;
98 100
99 /** 101 /**
100 - * Requests the device to transmit a given byte sequence over the given port. 102 + * Requests the device to transmit a given packet over the given port.
101 * 103 *
102 * @param portNumber a port number 104 * @param portNumber a port number
103 * @param packet a byte sequence 105 * @param packet a byte sequence
...@@ -106,7 +108,7 @@ public interface Bmv2DeviceAgent { ...@@ -106,7 +108,7 @@ public interface Bmv2DeviceAgent {
106 void transmitPacket(int portNumber, ImmutableByteSequence packet) throws Bmv2RuntimeException; 108 void transmitPacket(int portNumber, ImmutableByteSequence packet) throws Bmv2RuntimeException;
107 109
108 /** 110 /**
109 - * Resets the state of the switch (e.g. delete all entries, etc.). 111 + * Resets the state of the switch.
110 * 112 *
111 * @throws Bmv2RuntimeException if any error occurs 113 * @throws Bmv2RuntimeException if any error occurs
112 */ 114 */
...@@ -121,7 +123,7 @@ public interface Bmv2DeviceAgent { ...@@ -121,7 +123,7 @@ public interface Bmv2DeviceAgent {
121 String dumpJsonConfig() throws Bmv2RuntimeException; 123 String dumpJsonConfig() throws Bmv2RuntimeException;
122 124
123 /** 125 /**
124 - * Returns the md5 sum of the JSON-formatted model configuration currently used to process packets. 126 + * Returns the MD5 sum of the JSON-formatted configuration currently used to process packets.
125 * 127 *
126 * @return a string value 128 * @return a string value
127 * @throws Bmv2RuntimeException if any error occurs 129 * @throws Bmv2RuntimeException if any error occurs
...@@ -139,7 +141,7 @@ public interface Bmv2DeviceAgent { ...@@ -139,7 +141,7 @@ public interface Bmv2DeviceAgent {
139 Pair<Long, Long> readTableEntryCounter(String tableName, long entryId) throws Bmv2RuntimeException; 141 Pair<Long, Long> readTableEntryCounter(String tableName, long entryId) throws Bmv2RuntimeException;
140 142
141 /** 143 /**
142 - * Returns the counter values for a given counter and index. 144 + * Returns the values of a given counter instance.
143 * 145 *
144 * @param counterName a counter name 146 * @param counterName a counter name
145 * @param index an integer value 147 * @param index an integer value
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 import org.onlab.util.ImmutableByteSequence; 22 import org.onlab.util.ImmutableByteSequence;
...@@ -23,8 +24,9 @@ import org.onlab.util.ImmutableByteSequence; ...@@ -23,8 +24,9 @@ import org.onlab.util.ImmutableByteSequence;
23 import static com.google.common.base.Preconditions.checkNotNull; 24 import static com.google.common.base.Preconditions.checkNotNull;
24 25
25 /** 26 /**
26 - * Representation of a BMv2 exact match parameter. 27 + * A BMv2 exact match parameter.
27 */ 28 */
29 +@Beta
28 public final class Bmv2ExactMatchParam implements Bmv2MatchParam { 30 public final class Bmv2ExactMatchParam implements Bmv2MatchParam {
29 31
30 private final ImmutableByteSequence value; 32 private final ImmutableByteSequence value;
...@@ -45,7 +47,7 @@ public final class Bmv2ExactMatchParam implements Bmv2MatchParam { ...@@ -45,7 +47,7 @@ public final class Bmv2ExactMatchParam implements Bmv2MatchParam {
45 } 47 }
46 48
47 /** 49 /**
48 - * Return the byte sequence value matched by this parameter. 50 + * Return the byte sequence matched by this parameter.
49 * 51 *
50 * @return an immutable byte buffer value 52 * @return an immutable byte buffer value
51 */ 53 */
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 import org.onlab.util.KryoNamespace; 22 import org.onlab.util.KryoNamespace;
...@@ -31,6 +32,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -31,6 +32,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
31 /** 32 /**
32 * Extension selector for BMv2 used as a wrapper for multiple BMv2 match parameters. 33 * Extension selector for BMv2 used as a wrapper for multiple BMv2 match parameters.
33 */ 34 */
35 +@Beta
34 public final class Bmv2ExtensionSelector extends AbstractExtension implements ExtensionSelector { 36 public final class Bmv2ExtensionSelector extends AbstractExtension implements ExtensionSelector {
35 37
36 private final KryoNamespace appKryo = new KryoNamespace.Builder() 38 private final KryoNamespace appKryo = new KryoNamespace.Builder()
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 import org.onlab.util.KryoNamespace; 22 import org.onlab.util.KryoNamespace;
...@@ -28,16 +29,27 @@ import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.Exten ...@@ -28,16 +29,27 @@ import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.Exten
28 /** 29 /**
29 * Extension treatment for BMv2 used as a wrapper for a {@link Bmv2Action}. 30 * Extension treatment for BMv2 used as a wrapper for a {@link Bmv2Action}.
30 */ 31 */
32 +@Beta
31 public final class Bmv2ExtensionTreatment extends AbstractExtension implements ExtensionTreatment { 33 public final class Bmv2ExtensionTreatment extends AbstractExtension implements ExtensionTreatment {
32 34
33 private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); 35 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
34 private Bmv2Action action; 36 private Bmv2Action action;
35 37
38 + /**
39 + * Creates a new extension treatment for the given BMv2 action.
40 + *
41 + * @param action an action
42 + */
36 public Bmv2ExtensionTreatment(Bmv2Action action) { 43 public Bmv2ExtensionTreatment(Bmv2Action action) {
37 this.action = action; 44 this.action = action;
38 } 45 }
39 46
40 - public Bmv2Action getAction() { 47 + /**
48 + * Returns the action contained by this extension selector.
49 + *
50 + * @return an action
51 + */
52 + public Bmv2Action action() {
41 return action; 53 return action;
42 } 54 }
43 55
......
...@@ -16,15 +16,17 @@ ...@@ -16,15 +16,17 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.Objects; 20 import com.google.common.base.Objects;
20 import org.onosproject.net.flow.FlowRule; 21 import org.onosproject.net.flow.FlowRule;
21 22
22 import java.util.Date; 23 import java.util.Date;
23 24
24 /** 25 /**
25 - * A wrapper class for a ONOS flow rule installed on a BMv2 device. 26 + * A wrapper for a ONOS flow rule installed on a BMv2 device.
26 */ 27 */
27 -public class Bmv2FlowRuleWrapper { 28 +@Beta
29 +public final class Bmv2FlowRuleWrapper {
28 30
29 private final FlowRule rule; 31 private final FlowRule rule;
30 private final long entryId; 32 private final long entryId;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 import org.onlab.util.ImmutableByteSequence; 22 import org.onlab.util.ImmutableByteSequence;
...@@ -24,8 +25,9 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -24,8 +25,9 @@ import static com.google.common.base.Preconditions.checkArgument;
24 import static com.google.common.base.Preconditions.checkNotNull; 25 import static com.google.common.base.Preconditions.checkNotNull;
25 26
26 /** 27 /**
27 - * Representation of a BMv2 longest prefix match (LPM) parameter. 28 + * A BMv2 longest prefix match (LPM) parameter.
28 */ 29 */
30 +@Beta
29 public final class Bmv2LpmMatchParam implements Bmv2MatchParam { 31 public final class Bmv2LpmMatchParam implements Bmv2MatchParam {
30 32
31 private final ImmutableByteSequence value; 33 private final ImmutableByteSequence value;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.collect.Lists; 21 import com.google.common.collect.Lists;
21 import org.onlab.util.ImmutableByteSequence; 22 import org.onlab.util.ImmutableByteSequence;
...@@ -30,6 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -30,6 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
30 /** 31 /**
31 * A match key of a BMv2 match-action table entry. 32 * A match key of a BMv2 match-action table entry.
32 */ 33 */
34 +@Beta
33 public final class Bmv2MatchKey { 35 public final class Bmv2MatchKey {
34 36
35 private final List<Bmv2MatchParam> matchParams; 37 private final List<Bmv2MatchParam> matchParams;
......
...@@ -16,9 +16,12 @@ ...@@ -16,9 +16,12 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
20 +
19 /** 21 /**
20 * Representation of a BMv2 match parameter. 22 * Representation of a BMv2 match parameter.
21 */ 23 */
24 +@Beta
22 public interface Bmv2MatchParam { 25 public interface Bmv2MatchParam {
23 26
24 /** 27 /**
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 22
22 /** 23 /**
23 * Representation of a table entry installed on a BMv2 device. 24 * Representation of a table entry installed on a BMv2 device.
24 */ 25 */
26 +@Beta
25 public final class Bmv2ParsedTableEntry { 27 public final class Bmv2ParsedTableEntry {
26 private final long entryId; 28 private final long entryId;
27 private final Bmv2MatchKey matchKey; 29 private final Bmv2MatchKey matchKey;
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 22
22 /** 23 /**
23 * Information of a port of a BMv2 device. 24 * Information of a port of a BMv2 device.
24 */ 25 */
26 +@Beta
25 public final class Bmv2PortInfo { 27 public final class Bmv2PortInfo {
26 28
27 private final String ifaceName; 29 private final String ifaceName;
......
...@@ -16,9 +16,12 @@ ...@@ -16,9 +16,12 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
20 +
19 /** 21 /**
20 * General exception of the BMv2 runtime APIs. 22 * General exception of the BMv2 runtime APIs.
21 */ 23 */
24 +@Beta
22 public final class Bmv2RuntimeException extends Exception { 25 public final class Bmv2RuntimeException extends Exception {
23 26
24 private final Code code; 27 private final Code code;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
20 +
19 import java.util.Objects; 21 import java.util.Objects;
20 22
21 import static com.google.common.base.Preconditions.checkArgument; 23 import static com.google.common.base.Preconditions.checkArgument;
...@@ -24,6 +26,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -24,6 +26,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
24 /** 26 /**
25 * An entry of a match-action table in a BMv2 device. 27 * An entry of a match-action table in a BMv2 device.
26 */ 28 */
29 +@Beta
27 public final class Bmv2TableEntry { 30 public final class Bmv2TableEntry {
28 31
29 private static final int NO_PRIORITY_VALUE = -1; 32 private static final int NO_PRIORITY_VALUE = -1;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
...@@ -23,6 +24,7 @@ import org.onosproject.net.DeviceId; ...@@ -23,6 +24,7 @@ import org.onosproject.net.DeviceId;
23 /** 24 /**
24 * A reference to a table entry installed on a BMv2 device. 25 * A reference to a table entry installed on a BMv2 device.
25 */ 26 */
27 +@Beta
26 public final class Bmv2TableEntryReference { 28 public final class Bmv2TableEntryReference {
27 29
28 30
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 +import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 20 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 21 import com.google.common.base.Objects;
21 import org.onlab.util.ImmutableByteSequence; 22 import org.onlab.util.ImmutableByteSequence;
...@@ -26,6 +27,7 @@ import static com.google.common.base.Preconditions.checkState; ...@@ -26,6 +27,7 @@ import static com.google.common.base.Preconditions.checkState;
26 /** 27 /**
27 * Representation of a BMv2 ternary match parameter. 28 * Representation of a BMv2 ternary match parameter.
28 */ 29 */
30 +@Beta
29 public final class Bmv2TernaryMatchParam implements Bmv2MatchParam { 31 public final class Bmv2TernaryMatchParam implements Bmv2MatchParam {
30 32
31 private final ImmutableByteSequence value; 33 private final ImmutableByteSequence value;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 package org.onosproject.bmv2.api.runtime; 17 package org.onosproject.bmv2.api.runtime;
18 18
19 19
20 +import com.google.common.annotations.Beta;
20 import com.google.common.base.MoreObjects; 21 import com.google.common.base.MoreObjects;
21 22
22 import java.util.Objects; 23 import java.util.Objects;
...@@ -24,6 +25,7 @@ import java.util.Objects; ...@@ -24,6 +25,7 @@ import java.util.Objects;
24 /** 25 /**
25 * Representation of a BMv2 valid match parameter. 26 * Representation of a BMv2 valid match parameter.
26 */ 27 */
28 +@Beta
27 public final class Bmv2ValidMatchParam implements Bmv2MatchParam { 29 public final class Bmv2ValidMatchParam implements Bmv2MatchParam {
28 30
29 private final boolean flag; 31 private final boolean flag;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.service; 17 package org.onosproject.bmv2.api.service;
18 18
19 +import com.google.common.annotations.Beta;
19 import org.onosproject.bmv2.api.runtime.Bmv2DeviceAgent; 20 import org.onosproject.bmv2.api.runtime.Bmv2DeviceAgent;
20 import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException; 21 import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException;
21 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
...@@ -23,6 +24,7 @@ import org.onosproject.net.DeviceId; ...@@ -23,6 +24,7 @@ import org.onosproject.net.DeviceId;
23 /** 24 /**
24 * A controller of BMv2 devices. 25 * A controller of BMv2 devices.
25 */ 26 */
27 +@Beta
26 public interface Bmv2Controller { 28 public interface Bmv2Controller {
27 29
28 /** 30 /**
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.service; 17 package org.onosproject.bmv2.api.service;
18 18
19 +import com.google.common.annotations.Beta;
19 import org.onosproject.bmv2.api.context.Bmv2DeviceContext; 20 import org.onosproject.bmv2.api.context.Bmv2DeviceContext;
20 import org.onosproject.bmv2.api.context.Bmv2Interpreter; 21 import org.onosproject.bmv2.api.context.Bmv2Interpreter;
21 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
...@@ -23,6 +24,7 @@ import org.onosproject.net.DeviceId; ...@@ -23,6 +24,7 @@ import org.onosproject.net.DeviceId;
23 /** 24 /**
24 * A service for managing BMv2 device contexts. 25 * A service for managing BMv2 device contexts.
25 */ 26 */
27 +@Beta
26 public interface Bmv2DeviceContextService { 28 public interface Bmv2DeviceContextService {
27 29
28 /** 30 /**
......
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
16 16
17 package org.onosproject.bmv2.api.service; 17 package org.onosproject.bmv2.api.service;
18 18
19 +import com.google.common.annotations.Beta;
19 import org.onosproject.bmv2.api.runtime.Bmv2Device; 20 import org.onosproject.bmv2.api.runtime.Bmv2Device;
20 21
21 /** 22 /**
22 * A listener of BMv2 device events. 23 * A listener of BMv2 device events.
23 */ 24 */
25 +@Beta
24 public interface Bmv2DeviceListener { 26 public interface Bmv2DeviceListener {
25 27
26 /** 28 /**
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
16 16
17 package org.onosproject.bmv2.api.service; 17 package org.onosproject.bmv2.api.service;
18 18
19 +import com.google.common.annotations.Beta;
19 import org.onlab.util.ImmutableByteSequence; 20 import org.onlab.util.ImmutableByteSequence;
20 import org.onosproject.bmv2.api.runtime.Bmv2Device; 21 import org.onosproject.bmv2.api.runtime.Bmv2Device;
21 22
22 /** 23 /**
23 * A listener of BMv2 packet events. 24 * A listener of BMv2 packet events.
24 */ 25 */
26 +@Beta
25 public interface Bmv2PacketListener { 27 public interface Bmv2PacketListener {
26 28
27 /** 29 /**
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 package org.onosproject.bmv2.api.service; 17 package org.onosproject.bmv2.api.service;
18 18
19 19
20 +import com.google.common.annotations.Beta;
20 import org.onosproject.bmv2.api.context.Bmv2FlowRuleTranslator; 21 import org.onosproject.bmv2.api.context.Bmv2FlowRuleTranslator;
21 import org.onosproject.bmv2.api.runtime.Bmv2FlowRuleWrapper; 22 import org.onosproject.bmv2.api.runtime.Bmv2FlowRuleWrapper;
22 import org.onosproject.bmv2.api.runtime.Bmv2TableEntryReference; 23 import org.onosproject.bmv2.api.runtime.Bmv2TableEntryReference;
...@@ -24,6 +25,7 @@ import org.onosproject.bmv2.api.runtime.Bmv2TableEntryReference; ...@@ -24,6 +25,7 @@ import org.onosproject.bmv2.api.runtime.Bmv2TableEntryReference;
24 /** 25 /**
25 * A service for managing BMv2 table entries. 26 * A service for managing BMv2 table entries.
26 */ 27 */
28 +@Beta
27 public interface Bmv2TableEntryService { 29 public interface Bmv2TableEntryService {
28 30
29 /** 31 /**
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.bmv2.api.utils; 17 package org.onosproject.bmv2.api.utils;
18 18
19 +import com.google.common.annotations.Beta;
19 import org.onlab.util.HexString; 20 import org.onlab.util.HexString;
20 import org.onlab.util.ImmutableByteSequence; 21 import org.onlab.util.ImmutableByteSequence;
21 22
...@@ -25,8 +26,9 @@ import static com.google.common.base.Preconditions.checkArgument; ...@@ -25,8 +26,9 @@ import static com.google.common.base.Preconditions.checkArgument;
25 import static com.google.common.base.Preconditions.checkNotNull; 26 import static com.google.common.base.Preconditions.checkNotNull;
26 27
27 /** 28 /**
28 - * Collection of util methods to deal with flow rule translation. 29 + * Collection of utility methods to deal with flow rule translation.
29 */ 30 */
31 +@Beta
30 public final class Bmv2TranslatorUtils { 32 public final class Bmv2TranslatorUtils {
31 33
32 private Bmv2TranslatorUtils() { 34 private Bmv2TranslatorUtils() {
......
...@@ -22,11 +22,14 @@ import org.onosproject.bmv2.api.context.Bmv2Configuration; ...@@ -22,11 +22,14 @@ import org.onosproject.bmv2.api.context.Bmv2Configuration;
22 import org.onosproject.bmv2.api.context.Bmv2Interpreter; 22 import org.onosproject.bmv2.api.context.Bmv2Interpreter;
23 import org.onosproject.bmv2.api.context.Bmv2InterpreterException; 23 import org.onosproject.bmv2.api.context.Bmv2InterpreterException;
24 import org.onosproject.bmv2.api.runtime.Bmv2Action; 24 import org.onosproject.bmv2.api.runtime.Bmv2Action;
25 -import org.onosproject.bmv2.api.utils.Bmv2TranslatorUtils; 25 +import org.onosproject.net.PortNumber;
26 import org.onosproject.net.flow.TrafficTreatment; 26 import org.onosproject.net.flow.TrafficTreatment;
27 import org.onosproject.net.flow.criteria.Criterion; 27 import org.onosproject.net.flow.criteria.Criterion;
28 import org.onosproject.net.flow.instructions.Instruction; 28 import org.onosproject.net.flow.instructions.Instruction;
29 29
30 +import static org.onlab.util.ImmutableByteSequence.copyFrom;
31 +import static org.onosproject.bmv2.api.utils.Bmv2TranslatorUtils.ByteSequenceFitException;
32 +import static org.onosproject.bmv2.api.utils.Bmv2TranslatorUtils.fitByteSequence;
30 import static org.onosproject.net.PortNumber.CONTROLLER; 33 import static org.onosproject.net.PortNumber.CONTROLLER;
31 import static org.onosproject.net.flow.instructions.Instructions.OutputInstruction; 34 import static org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
32 35
...@@ -37,10 +40,10 @@ public final class Bmv2DefaultInterpreterImpl implements Bmv2Interpreter { ...@@ -37,10 +40,10 @@ public final class Bmv2DefaultInterpreterImpl implements Bmv2Interpreter {
37 40
38 public static final String TABLE0 = "table0"; 41 public static final String TABLE0 = "table0";
39 public static final String SEND_TO_CPU = "send_to_cpu"; 42 public static final String SEND_TO_CPU = "send_to_cpu";
43 + public static final String PORT = "port";
40 public static final String DROP = "_drop"; 44 public static final String DROP = "_drop";
41 public static final String SET_EGRESS_PORT = "set_egress_port"; 45 public static final String SET_EGRESS_PORT = "set_egress_port";
42 46
43 - // Lazily populate field map.
44 private static final ImmutableBiMap<Criterion.Type, String> CRITERION_MAP = ImmutableBiMap.of( 47 private static final ImmutableBiMap<Criterion.Type, String> CRITERION_MAP = ImmutableBiMap.of(
45 Criterion.Type.IN_PORT, "standard_metadata.ingress_port", 48 Criterion.Type.IN_PORT, "standard_metadata.ingress_port",
46 Criterion.Type.ETH_DST, "ethernet.dstAddr", 49 Criterion.Type.ETH_DST, "ethernet.dstAddr",
...@@ -64,10 +67,9 @@ public final class Bmv2DefaultInterpreterImpl implements Bmv2Interpreter { ...@@ -64,10 +67,9 @@ public final class Bmv2DefaultInterpreterImpl implements Bmv2Interpreter {
64 public Bmv2Action mapTreatment(TrafficTreatment treatment, Bmv2Configuration configuration) 67 public Bmv2Action mapTreatment(TrafficTreatment treatment, Bmv2Configuration configuration)
65 throws Bmv2InterpreterException { 68 throws Bmv2InterpreterException {
66 69
67 -
68 if (treatment.allInstructions().size() == 0) { 70 if (treatment.allInstructions().size() == 0) {
69 // No instructions means drop for us. 71 // No instructions means drop for us.
70 - return Bmv2Action.builder().withName(DROP).build(); 72 + return actionWithName(DROP);
71 } else if (treatment.allInstructions().size() > 1) { 73 } else if (treatment.allInstructions().size() > 1) {
72 // Otherwise, we understand treatments with only 1 instruction. 74 // Otherwise, we understand treatments with only 1 instruction.
73 throw new Bmv2InterpreterException("Treatment has multiple instructions"); 75 throw new Bmv2InterpreterException("Treatment has multiple instructions");
...@@ -78,47 +80,38 @@ public final class Bmv2DefaultInterpreterImpl implements Bmv2Interpreter { ...@@ -78,47 +80,38 @@ public final class Bmv2DefaultInterpreterImpl implements Bmv2Interpreter {
78 switch (instruction.type()) { 80 switch (instruction.type()) {
79 case OUTPUT: 81 case OUTPUT:
80 OutputInstruction outInstruction = (OutputInstruction) instruction; 82 OutputInstruction outInstruction = (OutputInstruction) instruction;
81 - if (outInstruction.port() == CONTROLLER) { 83 + PortNumber port = outInstruction.port();
82 - return Bmv2Action.builder().withName(SEND_TO_CPU).build(); 84 + if (!port.isLogical()) {
85 + return buildEgressAction(port, configuration);
86 + } else if (port.equals(CONTROLLER)) {
87 + return actionWithName(SEND_TO_CPU);
83 } else { 88 } else {
84 - return buildEgressAction(outInstruction, configuration); 89 + throw new Bmv2InterpreterException("Egress on logical port not supported: " + port);
85 } 90 }
86 case NOACTION: 91 case NOACTION:
87 - return Bmv2Action.builder().withName(DROP).build(); 92 + return actionWithName(DROP);
88 default: 93 default:
89 throw new Bmv2InterpreterException("Instruction type not supported: " + instruction.type().name()); 94 throw new Bmv2InterpreterException("Instruction type not supported: " + instruction.type().name());
90 } 95 }
91 } 96 }
92 97
93 - 98 + private Bmv2Action buildEgressAction(PortNumber port, Bmv2Configuration configuration)
94 - /**
95 - * Builds an egress action equivalent to the given output instruction for the given configuration.
96 - *
97 - * @param instruction an output instruction
98 - * @param configuration a configuration
99 - * @return a BMv2 action
100 - * @throws Bmv2InterpreterException if the instruction cannot be translated to a BMv2 action
101 - */
102 - private Bmv2Action buildEgressAction(OutputInstruction instruction, Bmv2Configuration configuration)
103 throws Bmv2InterpreterException { 99 throws Bmv2InterpreterException {
104 100
105 - Bmv2Action.Builder actionBuilder = Bmv2Action.builder(); 101 + int portBitWidth = configuration.action(SET_EGRESS_PORT).runtimeData(PORT).bitWidth();
106 102
107 - actionBuilder.withName(SET_EGRESS_PORT);
108 -
109 - if (instruction.port().isLogical()) {
110 - throw new Bmv2InterpreterException("Output on logic port not supported: " + instruction);
111 - }
112 -
113 - // Get the byte sequence for the out port with the right length
114 - long portNumber = instruction.port().toLong();
115 - int bitWidth = configuration.action(SET_EGRESS_PORT).runtimeData("port").bitWidth();
116 try { 103 try {
117 - ImmutableByteSequence outPort = Bmv2TranslatorUtils.fitByteSequence( 104 + ImmutableByteSequence portBs = fitByteSequence(copyFrom(port.toLong()), portBitWidth);
118 - ImmutableByteSequence.copyFrom(portNumber), bitWidth); 105 + return Bmv2Action.builder()
119 - return Bmv2Action.builder().withName(SET_EGRESS_PORT).addParameter(outPort).build(); 106 + .withName(SET_EGRESS_PORT)
120 - } catch (Bmv2TranslatorUtils.ByteSequenceFitException e) { 107 + .addParameter(portBs)
108 + .build();
109 + } catch (ByteSequenceFitException e) {
121 throw new Bmv2InterpreterException(e.getMessage()); 110 throw new Bmv2InterpreterException(e.getMessage());
122 } 111 }
123 } 112 }
113 +
114 + private Bmv2Action actionWithName(String name) {
115 + return Bmv2Action.builder().withName(name).build();
116 + }
124 } 117 }
......
...@@ -241,7 +241,7 @@ public class Bmv2FlowRuleTranslatorImpl implements Bmv2FlowRuleTranslator { ...@@ -241,7 +241,7 @@ public class Bmv2FlowRuleTranslatorImpl implements Bmv2FlowRuleTranslator {
241 241
242 if (extTreatment.type() == ExtensionTreatmentTypes.BMV2_ACTION.type()) { 242 if (extTreatment.type() == ExtensionTreatmentTypes.BMV2_ACTION.type()) {
243 if (extTreatment instanceof Bmv2ExtensionTreatment) { 243 if (extTreatment instanceof Bmv2ExtensionTreatment) {
244 - return ((Bmv2ExtensionTreatment) extTreatment).getAction(); 244 + return ((Bmv2ExtensionTreatment) extTreatment).action();
245 } else { 245 } else {
246 throw new Bmv2FlowRuleTranslatorException("Unable to decode treatment extension: " + extTreatment); 246 throw new Bmv2FlowRuleTranslatorException("Unable to decode treatment extension: " + extTreatment);
247 } 247 }
......