Committed by
Gerrit Code Review
Major refactoring of the BMv2 protocol module
- Created 3 separate sub-modules: API (doesn't depend on Thrift), CTL (depends on Thrift), THRIFT-API (to generate Thrift sources) - Implemented 2 new services (for device configuration swapping and table entry management) needed to distribute BMv2-specific state among ONOS instances. - Implemented a BMv2 controller (previously other modules where using separately a Thrift client and a server) - Added a default BMv2 JSON configuration (default.json) and interpreter to be used for devices that connect for the first time to ONOS. This allows for basic services to work (i.e. LLDP link discovery, ARP proxy. etc.). - Changed behavior of the flow rule translator and extension selector, now it allows extension to specify only some of the match parameters (before extension selectors were expected to describe the whole match key, i.e. all fields) - Various renaming to better represent the API - Various java doc fixes / improvements Change-Id: Ida4b5e546b0def97c3552a6c05f7bce76fd32c28
Showing
72 changed files
with
2620 additions
and
543 deletions
... | @@ -39,7 +39,7 @@ public class ExtensionSelectorType { | ... | @@ -39,7 +39,7 @@ public class ExtensionSelectorType { |
39 | NICIRA_MATCH_NSH_CH3(4), | 39 | NICIRA_MATCH_NSH_CH3(4), |
40 | NICIRA_MATCH_NSH_CH4(5), | 40 | NICIRA_MATCH_NSH_CH4(5), |
41 | OFDPA_MATCH_VLAN_VID(16), | 41 | OFDPA_MATCH_VLAN_VID(16), |
42 | - P4_BMV2_MATCH_KEY(128); | 42 | + BMV2_MATCH_PARAMS(128); |
43 | 43 | ||
44 | private ExtensionSelectorType type; | 44 | private ExtensionSelectorType type; |
45 | 45 | ... | ... |
... | @@ -46,7 +46,7 @@ public final class ExtensionTreatmentType { | ... | @@ -46,7 +46,7 @@ public final class ExtensionTreatmentType { |
46 | NICIRA_SET_NSH_CH3(36), | 46 | NICIRA_SET_NSH_CH3(36), |
47 | NICIRA_SET_NSH_CH4(37), | 47 | NICIRA_SET_NSH_CH4(37), |
48 | OFDPA_SET_VLAN_ID(64), | 48 | OFDPA_SET_VLAN_ID(64), |
49 | - P4_BMV2_ACTION(128); | 49 | + BMV2_ACTION(128); |
50 | 50 | ||
51 | private ExtensionTreatmentType type; | 51 | private ExtensionTreatmentType type; |
52 | 52 | ... | ... |
... | @@ -33,6 +33,7 @@ import org.onlab.packet.VlanId; | ... | @@ -33,6 +33,7 @@ import org.onlab.packet.VlanId; |
33 | import org.onlab.util.Bandwidth; | 33 | import org.onlab.util.Bandwidth; |
34 | import org.onlab.util.ClosedOpenRange; | 34 | import org.onlab.util.ClosedOpenRange; |
35 | import org.onlab.util.Frequency; | 35 | import org.onlab.util.Frequency; |
36 | +import org.onlab.util.ImmutableByteSequence; | ||
36 | import org.onlab.util.KryoNamespace; | 37 | import org.onlab.util.KryoNamespace; |
37 | import org.onlab.util.Match; | 38 | import org.onlab.util.Match; |
38 | import org.onosproject.app.ApplicationState; | 39 | import org.onosproject.app.ApplicationState; |
... | @@ -542,6 +543,7 @@ public final class KryoNamespaces { | ... | @@ -542,6 +543,7 @@ public final class KryoNamespaces { |
542 | .register(VlanCodec.class) | 543 | .register(VlanCodec.class) |
543 | .register(MplsCodec.class) | 544 | .register(MplsCodec.class) |
544 | .register(NoOpCodec.class) | 545 | .register(NoOpCodec.class) |
546 | + .register(ImmutableByteSequence.class) | ||
545 | .build("API"); | 547 | .build("API"); |
546 | 548 | ||
547 | 549 | ... | ... |
... | @@ -41,7 +41,7 @@ | ... | @@ -41,7 +41,7 @@ |
41 | <module>utilities</module> | 41 | <module>utilities</module> |
42 | <module>lumentum</module> | 42 | <module>lumentum</module> |
43 | <module>bti</module> | 43 | <module>bti</module> |
44 | - <module>bmv2</module> | 44 | + <!--<module>bmv2</module>--> |
45 | <module>corsa</module> | 45 | <module>corsa</module> |
46 | <module>optical</module> | 46 | <module>optical</module> |
47 | </modules> | 47 | </modules> | ... | ... |
protocols/bmv2/api/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | + | ||
18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
19 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
20 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
21 | + <parent> | ||
22 | + <artifactId>onos-bmv2-protocol</artifactId> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <version>1.6.0-SNAPSHOT</version> | ||
25 | + </parent> | ||
26 | + <modelVersion>4.0.0</modelVersion> | ||
27 | + | ||
28 | + <packaging>bundle</packaging> | ||
29 | + | ||
30 | + <artifactId>onos-bmv2-protocol-api</artifactId> | ||
31 | + | ||
32 | + <dependencies> | ||
33 | + <dependency> | ||
34 | + <groupId>org.onosproject</groupId> | ||
35 | + <artifactId>onos-api</artifactId> | ||
36 | + <version>${project.version}</version> | ||
37 | + </dependency> | ||
38 | + <dependency> | ||
39 | + <groupId>org.apache.felix</groupId> | ||
40 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
41 | + </dependency> | ||
42 | + </dependencies> | ||
43 | + | ||
44 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -14,8 +14,9 @@ | ... | @@ -14,8 +14,9 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
18 | 18 | ||
19 | +import com.google.common.annotations.Beta; | ||
19 | import com.google.common.collect.ImmutableList; | 20 | import com.google.common.collect.ImmutableList; |
20 | import com.google.common.collect.Maps; | 21 | import com.google.common.collect.Maps; |
21 | 22 | ||
... | @@ -26,22 +27,23 @@ import java.util.Objects; | ... | @@ -26,22 +27,23 @@ import java.util.Objects; |
26 | import static com.google.common.base.MoreObjects.toStringHelper; | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
27 | 28 | ||
28 | /** | 29 | /** |
29 | - * BMv2 model action. | 30 | + * A BMv2 action model. |
30 | */ | 31 | */ |
31 | -public final class Bmv2ModelAction { | 32 | +@Beta |
33 | +public final class Bmv2ActionModel { | ||
32 | 34 | ||
33 | private final String name; | 35 | private final String name; |
34 | private final int id; | 36 | private final int id; |
35 | - private final LinkedHashMap<String, Bmv2ModelRuntimeData> runtimeDatas = Maps.newLinkedHashMap(); | 37 | + private final LinkedHashMap<String, Bmv2RuntimeDataModel> runtimeDatas = Maps.newLinkedHashMap(); |
36 | 38 | ||
37 | /** | 39 | /** |
38 | - * Creates a new action object. | 40 | + * Creates a new action model. |
39 | * | 41 | * |
40 | * @param name name | 42 | * @param name name |
41 | * @param id id | 43 | * @param id id |
42 | * @param runtimeDatas list of runtime data | 44 | * @param runtimeDatas list of runtime data |
43 | */ | 45 | */ |
44 | - protected Bmv2ModelAction(String name, int id, List<Bmv2ModelRuntimeData> runtimeDatas) { | 46 | + protected Bmv2ActionModel(String name, int id, List<Bmv2RuntimeDataModel> runtimeDatas) { |
45 | this.name = name; | 47 | this.name = name; |
46 | this.id = id; | 48 | this.id = id; |
47 | runtimeDatas.forEach(r -> this.runtimeDatas.put(r.name(), r)); | 49 | runtimeDatas.forEach(r -> this.runtimeDatas.put(r.name(), r)); |
... | @@ -66,22 +68,22 @@ public final class Bmv2ModelAction { | ... | @@ -66,22 +68,22 @@ public final class Bmv2ModelAction { |
66 | } | 68 | } |
67 | 69 | ||
68 | /** | 70 | /** |
69 | - * Returns this action's runtime data defined by the passed name, null | 71 | + * Returns this action's runtime data defined by the given name, null |
70 | * if not present. | 72 | * if not present. |
71 | * | 73 | * |
72 | * @return runtime data or null | 74 | * @return runtime data or null |
73 | */ | 75 | */ |
74 | - public Bmv2ModelRuntimeData runtimeData(String name) { | 76 | + public Bmv2RuntimeDataModel runtimeData(String name) { |
75 | return runtimeDatas.get(name); | 77 | return runtimeDatas.get(name); |
76 | } | 78 | } |
77 | 79 | ||
78 | /** | 80 | /** |
79 | * Returns an immutable list of runtime data for this action. | 81 | * Returns an immutable list of runtime data for this action. |
80 | - * The list is ordered according to the values defined in the model. | 82 | + * The list is ordered according to the values defined in the configuration. |
81 | * | 83 | * |
82 | * @return list of runtime data. | 84 | * @return list of runtime data. |
83 | */ | 85 | */ |
84 | - public List<Bmv2ModelRuntimeData> runtimeDatas() { | 86 | + public List<Bmv2RuntimeDataModel> runtimeDatas() { |
85 | return ImmutableList.copyOf(runtimeDatas.values()); | 87 | return ImmutableList.copyOf(runtimeDatas.values()); |
86 | } | 88 | } |
87 | 89 | ||
... | @@ -98,7 +100,7 @@ public final class Bmv2ModelAction { | ... | @@ -98,7 +100,7 @@ public final class Bmv2ModelAction { |
98 | if (obj == null || getClass() != obj.getClass()) { | 100 | if (obj == null || getClass() != obj.getClass()) { |
99 | return false; | 101 | return false; |
100 | } | 102 | } |
101 | - final Bmv2ModelAction other = (Bmv2ModelAction) obj; | 103 | + final Bmv2ActionModel other = (Bmv2ActionModel) obj; |
102 | return Objects.equals(this.name, other.name) | 104 | return Objects.equals(this.name, other.name) |
103 | && Objects.equals(this.id, other.id) | 105 | && Objects.equals(this.id, other.id) |
104 | && Objects.equals(this.runtimeDatas, other.runtimeDatas); | 106 | && Objects.equals(this.runtimeDatas, other.runtimeDatas); | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.context; | ||
18 | + | ||
19 | +import com.eclipsesource.json.JsonObject; | ||
20 | +import com.google.common.annotations.Beta; | ||
21 | + | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * BMv2 packet processing configuration. Such a configuration is used to define the way BMv2 should process packets | ||
26 | + * (i.e. it defines the device ingress/egress pipelines, parser, tables, actions, etc.). It must be noted that this | ||
27 | + * class exposes only a subset of the configuration properties of a BMv2 device (only those that are needed for the | ||
28 | + * purpose of translating ONOS structures to BMv2 structures). Such a configuration is backed by a JSON object. | ||
29 | + * BMv2 JSON configuration files are usually generated using a P4 frontend compiler such as p4c-bmv2. | ||
30 | + */ | ||
31 | +@Beta | ||
32 | +public interface Bmv2Configuration { | ||
33 | + | ||
34 | + /** | ||
35 | + * Return an unmodifiable view of the JSON backing this configuration. | ||
36 | + * | ||
37 | + * @return a JSON object. | ||
38 | + */ | ||
39 | + JsonObject json(); | ||
40 | + | ||
41 | + /** | ||
42 | + * Returns the header type associated with the given numeric ID, null if there's no such an ID in the configuration. | ||
43 | + * | ||
44 | + * @param id integer value | ||
45 | + * @return header type object or null | ||
46 | + */ | ||
47 | + Bmv2HeaderTypeModel headerType(int id); | ||
48 | + | ||
49 | + /** | ||
50 | + * Returns the header type associated with the given name, null if there's no such a name in the configuration. | ||
51 | + * | ||
52 | + * @param name string value | ||
53 | + * @return header type object or null | ||
54 | + */ | ||
55 | + Bmv2HeaderTypeModel headerType(String name); | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the list of all the header types defined by in this configuration. Values returned are sorted in | ||
59 | + * ascending order based on the numeric ID. | ||
60 | + * | ||
61 | + * @return list of header types | ||
62 | + */ | ||
63 | + List<Bmv2HeaderTypeModel> headerTypes(); | ||
64 | + | ||
65 | + /** | ||
66 | + * Returns the header associated with the given numeric ID, null if there's no such an ID in the configuration. | ||
67 | + * | ||
68 | + * @param id integer value | ||
69 | + * @return header object or null | ||
70 | + */ | ||
71 | + Bmv2HeaderModel header(int id); | ||
72 | + | ||
73 | + /** | ||
74 | + * Returns the header associated with the given name, null if there's no such a name in the configuration. | ||
75 | + * | ||
76 | + * @param name string value | ||
77 | + * @return header object or null | ||
78 | + */ | ||
79 | + Bmv2HeaderModel header(String name); | ||
80 | + | ||
81 | + /** | ||
82 | + * Returns the list of all the header instances defined in this configuration. Values returned are sorted in | ||
83 | + * ascending order based on the numeric ID. | ||
84 | + * | ||
85 | + * @return list of header types | ||
86 | + */ | ||
87 | + List<Bmv2HeaderModel> headers(); | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns the action associated with the given numeric ID, null if there's no such an ID in the configuration. | ||
91 | + * | ||
92 | + * @param id integer value | ||
93 | + * @return action object or null | ||
94 | + */ | ||
95 | + Bmv2ActionModel action(int id); | ||
96 | + | ||
97 | + /** | ||
98 | + * Returns the action associated with the given name, null if there's no such a name in the configuration. | ||
99 | + * | ||
100 | + * @param name string value | ||
101 | + * @return action object or null | ||
102 | + */ | ||
103 | + Bmv2ActionModel action(String name); | ||
104 | + | ||
105 | + /** | ||
106 | + * Returns the list of all the actions defined by in this configuration. Values returned are sorted in ascending | ||
107 | + * order based on the numeric ID. | ||
108 | + * | ||
109 | + * @return list of actions | ||
110 | + */ | ||
111 | + List<Bmv2ActionModel> actions(); | ||
112 | + | ||
113 | + /** | ||
114 | + * Returns the table associated with the given numeric ID, null if there's no such an ID in the configuration. | ||
115 | + * | ||
116 | + * @param id integer value | ||
117 | + * @return table object or null | ||
118 | + */ | ||
119 | + Bmv2TableModel table(int id); | ||
120 | + | ||
121 | + /** | ||
122 | + * Returns the table associated with the given name, null if there's no such a name in the configuration. | ||
123 | + * | ||
124 | + * @param name string value | ||
125 | + * @return table object or null | ||
126 | + */ | ||
127 | + Bmv2TableModel table(String name); | ||
128 | + | ||
129 | + /** | ||
130 | + * Returns the list of all the tables defined by in this configuration. Values returned are sorted in ascending | ||
131 | + * order based on the numeric ID. | ||
132 | + * | ||
133 | + * @return list of actions | ||
134 | + */ | ||
135 | + List<Bmv2TableModel> tables(); | ||
136 | +} |
This diff is collapsed. Click to expand it.
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.context; | ||
18 | + | ||
19 | +import com.google.common.annotations.Beta; | ||
20 | +import com.google.common.base.MoreObjects; | ||
21 | +import com.google.common.base.Objects; | ||
22 | + | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
25 | +/** | ||
26 | + * A BMv2 device context, defined by a configuration and an interpreter. | ||
27 | + */ | ||
28 | +@Beta | ||
29 | +public final class Bmv2DeviceContext { | ||
30 | + | ||
31 | + private final Bmv2Configuration configuration; | ||
32 | + private final Bmv2Interpreter interpreter; | ||
33 | + | ||
34 | + /** | ||
35 | + * Creates a new BMv2 device context. | ||
36 | + * | ||
37 | + * @param configuration a configuration | ||
38 | + * @param interpreter an interpreter | ||
39 | + */ | ||
40 | + public Bmv2DeviceContext(Bmv2Configuration configuration, Bmv2Interpreter interpreter) { | ||
41 | + this.configuration = checkNotNull(configuration, "configuration cannot be null"); | ||
42 | + this.interpreter = checkNotNull(interpreter, "interpreter cannot be null"); | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Returns the BMv2 configuration of this context. | ||
47 | + * | ||
48 | + * @return a configuration | ||
49 | + */ | ||
50 | + public Bmv2Configuration configuration() { | ||
51 | + return configuration; | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns the BMv2 interpreter of this context. | ||
56 | + * | ||
57 | + * @return an interpreter | ||
58 | + */ | ||
59 | + public Bmv2Interpreter interpreter() { | ||
60 | + return interpreter; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public int hashCode() { | ||
65 | + return Objects.hashCode(configuration, interpreter); | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public boolean equals(Object obj) { | ||
70 | + if (this == obj) { | ||
71 | + return true; | ||
72 | + } | ||
73 | + if (obj == null || getClass() != obj.getClass()) { | ||
74 | + return false; | ||
75 | + } | ||
76 | + final Bmv2DeviceContext other = (Bmv2DeviceContext) obj; | ||
77 | + return Objects.equal(this.configuration, other.configuration) | ||
78 | + && Objects.equal(this.interpreter, other.interpreter); | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public String toString() { | ||
83 | + return MoreObjects.toStringHelper(this) | ||
84 | + .add("configuration", configuration) | ||
85 | + .add("interpreter", interpreter) | ||
86 | + .toString(); | ||
87 | + } | ||
88 | +} |
... | @@ -14,21 +14,23 @@ | ... | @@ -14,21 +14,23 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
18 | 18 | ||
19 | +import com.google.common.annotations.Beta; | ||
19 | import com.google.common.base.Objects; | 20 | import com.google.common.base.Objects; |
20 | 21 | ||
21 | import static com.google.common.base.MoreObjects.toStringHelper; | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
22 | 23 | ||
23 | /** | 24 | /** |
24 | - * Representation of a BMv2 model's header field instance. | 25 | + * A BMv2 header field model. |
25 | */ | 26 | */ |
26 | -public final class Bmv2ModelField { | 27 | +@Beta |
28 | +public final class Bmv2FieldModel { | ||
27 | 29 | ||
28 | - private final Bmv2ModelHeader header; | 30 | + private final Bmv2HeaderModel header; |
29 | - private final Bmv2ModelFieldType type; | 31 | + private final Bmv2FieldTypeModel type; |
30 | 32 | ||
31 | - protected Bmv2ModelField(Bmv2ModelHeader header, Bmv2ModelFieldType type) { | 33 | + protected Bmv2FieldModel(Bmv2HeaderModel header, Bmv2FieldTypeModel type) { |
32 | this.header = header; | 34 | this.header = header; |
33 | this.type = type; | 35 | this.type = type; |
34 | } | 36 | } |
... | @@ -38,7 +40,7 @@ public final class Bmv2ModelField { | ... | @@ -38,7 +40,7 @@ public final class Bmv2ModelField { |
38 | * | 40 | * |
39 | * @return a header instance | 41 | * @return a header instance |
40 | */ | 42 | */ |
41 | - public Bmv2ModelHeader header() { | 43 | + public Bmv2HeaderModel header() { |
42 | return header; | 44 | return header; |
43 | } | 45 | } |
44 | 46 | ||
... | @@ -47,7 +49,7 @@ public final class Bmv2ModelField { | ... | @@ -47,7 +49,7 @@ public final class Bmv2ModelField { |
47 | * | 49 | * |
48 | * @return a field type value | 50 | * @return a field type value |
49 | */ | 51 | */ |
50 | - public Bmv2ModelFieldType type() { | 52 | + public Bmv2FieldTypeModel type() { |
51 | return type; | 53 | return type; |
52 | } | 54 | } |
53 | 55 | ||
... | @@ -64,7 +66,7 @@ public final class Bmv2ModelField { | ... | @@ -64,7 +66,7 @@ public final class Bmv2ModelField { |
64 | if (obj == null || getClass() != obj.getClass()) { | 66 | if (obj == null || getClass() != obj.getClass()) { |
65 | return false; | 67 | return false; |
66 | } | 68 | } |
67 | - final Bmv2ModelField other = (Bmv2ModelField) obj; | 69 | + final Bmv2FieldModel other = (Bmv2FieldModel) obj; |
68 | return Objects.equal(this.header, other.header) | 70 | return Objects.equal(this.header, other.header) |
69 | && Objects.equal(this.type, other.type); | 71 | && Objects.equal(this.type, other.type); |
70 | } | 72 | } | ... | ... |
... | @@ -14,21 +14,23 @@ | ... | @@ -14,21 +14,23 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
18 | 18 | ||
19 | +import com.google.common.annotations.Beta; | ||
19 | import com.google.common.base.Objects; | 20 | import com.google.common.base.Objects; |
20 | 21 | ||
21 | import static com.google.common.base.MoreObjects.toStringHelper; | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
22 | 23 | ||
23 | /** | 24 | /** |
24 | - * BMv2 model header type field. | 25 | + * A BMv2 header type field model. |
25 | */ | 26 | */ |
26 | -public final class Bmv2ModelFieldType { | 27 | +@Beta |
28 | +public final class Bmv2FieldTypeModel { | ||
27 | 29 | ||
28 | private final String name; | 30 | private final String name; |
29 | private final int bitWidth; | 31 | private final int bitWidth; |
30 | 32 | ||
31 | - protected Bmv2ModelFieldType(String name, int bitWidth) { | 33 | + protected Bmv2FieldTypeModel(String name, int bitWidth) { |
32 | this.name = name; | 34 | this.name = name; |
33 | this.bitWidth = bitWidth; | 35 | this.bitWidth = bitWidth; |
34 | } | 36 | } |
... | @@ -64,7 +66,7 @@ public final class Bmv2ModelFieldType { | ... | @@ -64,7 +66,7 @@ public final class Bmv2ModelFieldType { |
64 | if (obj == null || getClass() != obj.getClass()) { | 66 | if (obj == null || getClass() != obj.getClass()) { |
65 | return false; | 67 | return false; |
66 | } | 68 | } |
67 | - final Bmv2ModelFieldType other = (Bmv2ModelFieldType) obj; | 69 | + final Bmv2FieldTypeModel other = (Bmv2FieldTypeModel) obj; |
68 | return Objects.equal(this.name, other.name) | 70 | return Objects.equal(this.name, other.name) |
69 | && Objects.equal(this.bitWidth, other.bitWidth); | 71 | && Objects.equal(this.bitWidth, other.bitWidth); |
70 | } | 72 | } | ... | ... |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/context/Bmv2FlowRuleTranslator.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.context; | ||
18 | + | ||
19 | +import com.google.common.annotations.Beta; | ||
20 | +import org.onosproject.bmv2.api.runtime.Bmv2TableEntry; | ||
21 | +import org.onosproject.net.flow.FlowRule; | ||
22 | + | ||
23 | +/** | ||
24 | + * Translator of ONOS flow rules to BMv2 table entries. | ||
25 | + */ | ||
26 | +@Beta | ||
27 | +public interface Bmv2FlowRuleTranslator { | ||
28 | + | ||
29 | + /** | ||
30 | + * Returns a BMv2 table entry equivalent to the given flow rule for the given context. | ||
31 | + * <p> | ||
32 | + * Translation is performed according to the following logic: | ||
33 | + * <ul> | ||
34 | + * <li> table name: obtained from the context interpreter {@link Bmv2Interpreter#tableIdMap() table ID map}. | ||
35 | + * <li> match key: is built using both the context interpreter {@link Bmv2Interpreter#criterionTypeMap() criterion | ||
36 | + * map} and all {@link org.onosproject.bmv2.api.runtime.Bmv2ExtensionSelector extension selectors} (if any). | ||
37 | + * <li> action: is built using the context interpreter | ||
38 | + * {@link Bmv2Interpreter#mapTreatment(org.onosproject.net.flow.TrafficTreatment, Bmv2Configuration) | ||
39 | + * treatment mapping function} or the flow rule | ||
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 | ||
42 | + * entry). | ||
43 | + * </ul> | ||
44 | + * | ||
45 | + * @param rule a flow rule | ||
46 | + * @param context a context | ||
47 | + * @return a BMv2 table entry | ||
48 | + * @throws Bmv2FlowRuleTranslatorException if the flow rule cannot be translated | ||
49 | + */ | ||
50 | + Bmv2TableEntry translate(FlowRule rule, Bmv2DeviceContext context) throws Bmv2FlowRuleTranslatorException; | ||
51 | +} |
... | @@ -14,41 +14,14 @@ | ... | @@ -14,41 +14,14 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.runtime; | 17 | +package org.onosproject.bmv2.api.context; |
18 | - | ||
19 | -import org.onlab.util.KryoNamespace; | ||
20 | -import org.onosproject.net.flow.AbstractExtension; | ||
21 | -import org.onosproject.net.flow.criteria.ExtensionSelector; | ||
22 | -import org.onosproject.net.flow.criteria.ExtensionSelectorType; | ||
23 | 18 | ||
24 | /** | 19 | /** |
25 | - * Extension selector for Bmv2 used as a wrapper for a {@link Bmv2MatchKey}. | 20 | + * BMv2 flow rule translator exception. |
26 | */ | 21 | */ |
27 | -public class Bmv2ExtensionSelector extends AbstractExtension implements ExtensionSelector { | 22 | +public class Bmv2FlowRuleTranslatorException extends Exception { |
28 | - | ||
29 | - private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); | ||
30 | - private Bmv2MatchKey matchKey; | ||
31 | - | ||
32 | - public Bmv2ExtensionSelector(Bmv2MatchKey matchKey) { | ||
33 | - this.matchKey = matchKey; | ||
34 | - } | ||
35 | - | ||
36 | - public Bmv2MatchKey matchKey() { | ||
37 | - return matchKey; | ||
38 | - } | ||
39 | - | ||
40 | - @Override | ||
41 | - public ExtensionSelectorType type() { | ||
42 | - return ExtensionSelectorType.ExtensionSelectorTypes.P4_BMV2_MATCH_KEY.type(); | ||
43 | - } | ||
44 | - | ||
45 | - @Override | ||
46 | - public byte[] serialize() { | ||
47 | - return appKryo.serialize(matchKey); | ||
48 | - } | ||
49 | 23 | ||
50 | - @Override | 24 | + public Bmv2FlowRuleTranslatorException(String msg) { |
51 | - public void deserialize(byte[] data) { | 25 | + super(msg); |
52 | - matchKey = appKryo.deserialize(data); | ||
53 | } | 26 | } |
54 | } | 27 | } | ... | ... |
... | @@ -14,31 +14,33 @@ | ... | @@ -14,31 +14,33 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
18 | 18 | ||
19 | +import com.google.common.annotations.Beta; | ||
19 | import com.google.common.base.Objects; | 20 | import com.google.common.base.Objects; |
20 | 21 | ||
21 | import static com.google.common.base.MoreObjects.toStringHelper; | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
22 | 23 | ||
23 | /** | 24 | /** |
24 | - * Representation of a BMv2 model header instance. | 25 | + * BMv2 header instance model. |
25 | */ | 26 | */ |
26 | -public final class Bmv2ModelHeader { | 27 | +@Beta |
28 | +public final class Bmv2HeaderModel { | ||
27 | 29 | ||
28 | private final String name; | 30 | private final String name; |
29 | private final int id; | 31 | private final int id; |
30 | - private final Bmv2ModelHeaderType type; | 32 | + private final Bmv2HeaderTypeModel type; |
31 | private final boolean isMetadata; | 33 | private final boolean isMetadata; |
32 | 34 | ||
33 | /** | 35 | /** |
34 | - * Creates a new header instance. | 36 | + * Creates a new header instance model. |
35 | * | 37 | * |
36 | * @param name name | 38 | * @param name name |
37 | * @param id id | 39 | * @param id id |
38 | * @param type header type | 40 | * @param type header type |
39 | * @param metadata if is metadata | 41 | * @param metadata if is metadata |
40 | */ | 42 | */ |
41 | - protected Bmv2ModelHeader(String name, int id, Bmv2ModelHeaderType type, boolean metadata) { | 43 | + protected Bmv2HeaderModel(String name, int id, Bmv2HeaderTypeModel type, boolean metadata) { |
42 | this.name = name; | 44 | this.name = name; |
43 | this.id = id; | 45 | this.id = id; |
44 | this.type = type; | 46 | this.type = type; |
... | @@ -68,7 +70,7 @@ public final class Bmv2ModelHeader { | ... | @@ -68,7 +70,7 @@ public final class Bmv2ModelHeader { |
68 | * | 70 | * |
69 | * @return a header type value | 71 | * @return a header type value |
70 | */ | 72 | */ |
71 | - public Bmv2ModelHeaderType type() { | 73 | + public Bmv2HeaderTypeModel type() { |
72 | return type; | 74 | return type; |
73 | } | 75 | } |
74 | 76 | ||
... | @@ -94,7 +96,7 @@ public final class Bmv2ModelHeader { | ... | @@ -94,7 +96,7 @@ public final class Bmv2ModelHeader { |
94 | if (obj == null || getClass() != obj.getClass()) { | 96 | if (obj == null || getClass() != obj.getClass()) { |
95 | return false; | 97 | return false; |
96 | } | 98 | } |
97 | - final Bmv2ModelHeader other = (Bmv2ModelHeader) obj; | 99 | + final Bmv2HeaderModel other = (Bmv2HeaderModel) obj; |
98 | return Objects.equal(this.name, other.name) | 100 | return Objects.equal(this.name, other.name) |
99 | && Objects.equal(this.id, other.id) | 101 | && Objects.equal(this.id, other.id) |
100 | && Objects.equal(this.type, other.type) | 102 | && Objects.equal(this.type, other.type) | ... | ... |
... | @@ -14,8 +14,9 @@ | ... | @@ -14,8 +14,9 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
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 com.google.common.collect.ImmutableList; | 21 | import com.google.common.collect.ImmutableList; |
21 | import com.google.common.collect.Maps; | 22 | import com.google.common.collect.Maps; |
... | @@ -26,22 +27,23 @@ import java.util.List; | ... | @@ -26,22 +27,23 @@ import java.util.List; |
26 | import static com.google.common.base.MoreObjects.toStringHelper; | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
27 | 28 | ||
28 | /** | 29 | /** |
29 | - * BMv2 model header type. | 30 | + * BMv2 header type model. |
30 | */ | 31 | */ |
31 | -public final class Bmv2ModelHeaderType { | 32 | +@Beta |
33 | +public final class Bmv2HeaderTypeModel { | ||
32 | 34 | ||
33 | private final String name; | 35 | private final String name; |
34 | private final int id; | 36 | private final int id; |
35 | - private final LinkedHashMap<String, Bmv2ModelFieldType> fields = Maps.newLinkedHashMap(); | 37 | + private final LinkedHashMap<String, Bmv2FieldTypeModel> fields = Maps.newLinkedHashMap(); |
36 | 38 | ||
37 | /** | 39 | /** |
38 | - * Creates a new header type instance. | 40 | + * Creates a new header type model. |
39 | * | 41 | * |
40 | * @param name name | 42 | * @param name name |
41 | * @param id id | 43 | * @param id id |
42 | * @param fieldTypes fields | 44 | * @param fieldTypes fields |
43 | */ | 45 | */ |
44 | - protected Bmv2ModelHeaderType(String name, int id, List<Bmv2ModelFieldType> fieldTypes) { | 46 | + protected Bmv2HeaderTypeModel(String name, int id, List<Bmv2FieldTypeModel> fieldTypes) { |
45 | this.name = name; | 47 | this.name = name; |
46 | this.id = id; | 48 | this.id = id; |
47 | fieldTypes.forEach(f -> this.fields.put(f.name(), f)); | 49 | fieldTypes.forEach(f -> this.fields.put(f.name(), f)); |
... | @@ -72,7 +74,7 @@ public final class Bmv2ModelHeaderType { | ... | @@ -72,7 +74,7 @@ public final class Bmv2ModelHeaderType { |
72 | * @param fieldName field name | 74 | * @param fieldName field name |
73 | * @return field or null | 75 | * @return field or null |
74 | */ | 76 | */ |
75 | - public Bmv2ModelFieldType field(String fieldName) { | 77 | + public Bmv2FieldTypeModel field(String fieldName) { |
76 | return fields.get(fieldName); | 78 | return fields.get(fieldName); |
77 | } | 79 | } |
78 | 80 | ||
... | @@ -83,7 +85,7 @@ public final class Bmv2ModelHeaderType { | ... | @@ -83,7 +85,7 @@ public final class Bmv2ModelHeaderType { |
83 | * | 85 | * |
84 | * @return list of fields | 86 | * @return list of fields |
85 | */ | 87 | */ |
86 | - public List<Bmv2ModelFieldType> fields() { | 88 | + public List<Bmv2FieldTypeModel> fields() { |
87 | return ImmutableList.copyOf(fields.values()); | 89 | return ImmutableList.copyOf(fields.values()); |
88 | } | 90 | } |
89 | 91 | ||
... | @@ -100,7 +102,7 @@ public final class Bmv2ModelHeaderType { | ... | @@ -100,7 +102,7 @@ public final class Bmv2ModelHeaderType { |
100 | if (obj == null || getClass() != obj.getClass()) { | 102 | if (obj == null || getClass() != obj.getClass()) { |
101 | return false; | 103 | return false; |
102 | } | 104 | } |
103 | - final Bmv2ModelHeaderType other = (Bmv2ModelHeaderType) obj; | 105 | + final Bmv2HeaderTypeModel other = (Bmv2HeaderTypeModel) obj; |
104 | return Objects.equal(this.name, other.name) | 106 | return Objects.equal(this.name, other.name) |
105 | && Objects.equal(this.id, other.id) | 107 | && Objects.equal(this.id, other.id) |
106 | && Objects.equal(this.fields, other.fields); | 108 | && Objects.equal(this.fields, other.fields); | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.context; | ||
18 | + | ||
19 | +import com.google.common.annotations.Beta; | ||
20 | +import com.google.common.collect.ImmutableBiMap; | ||
21 | +import org.onosproject.bmv2.api.runtime.Bmv2Action; | ||
22 | +import org.onosproject.net.flow.TrafficTreatment; | ||
23 | +import org.onosproject.net.flow.criteria.Criterion; | ||
24 | + | ||
25 | +/** | ||
26 | + * A BMv2 configuration interpreter. | ||
27 | + */ | ||
28 | +@Beta | ||
29 | +public interface Bmv2Interpreter { | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns a bi-map describing a one-to-one relationship between ONOS flow rule table IDs and BMv2 table names. | ||
33 | + * | ||
34 | + * @return a {@link com.google.common.collect.BiMap} where the key is a ONOS flow rule table id and | ||
35 | + * the value is a BMv2 table names | ||
36 | + */ | ||
37 | + ImmutableBiMap<Integer, String> tableIdMap(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns a bi-map describing a one-to-one relationship between ONOS criterion types and BMv2 header field names. | ||
41 | + * Header field names are formatted using the notation {@code header_name.field_member_name}. | ||
42 | + * | ||
43 | + * @return a {@link com.google.common.collect.BiMap} where the keys are ONOS criterion types and the values are | ||
44 | + * BMv2 header field names | ||
45 | + */ | ||
46 | + ImmutableBiMap<Criterion.Type, String> criterionTypeMap(); | ||
47 | + | ||
48 | + /** | ||
49 | + * Return a BMv2 action that is functionally equivalent to the given ONOS traffic treatment for the given | ||
50 | + * configuration. | ||
51 | + * | ||
52 | + * @param treatment a ONOS traffic treatment | ||
53 | + * @param configuration a BMv2 configuration | ||
54 | + * @return a BMv2 action object | ||
55 | + * @throws Bmv2InterpreterException if the treatment cannot be mapped to any BMv2 action | ||
56 | + */ | ||
57 | + Bmv2Action mapTreatment(TrafficTreatment treatment, Bmv2Configuration configuration) | ||
58 | + throws Bmv2InterpreterException; | ||
59 | + | ||
60 | +} |
... | @@ -14,18 +14,14 @@ | ... | @@ -14,18 +14,14 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.runtime; | 17 | +package org.onosproject.bmv2.api.context; |
18 | 18 | ||
19 | /** | 19 | /** |
20 | - * General exception of the Bmv2 runtime APIs. | 20 | + * A BMv2 interpreter exception. |
21 | */ | 21 | */ |
22 | -public class Bmv2RuntimeException extends Exception { | 22 | +public class Bmv2InterpreterException extends Exception { |
23 | 23 | ||
24 | - public Bmv2RuntimeException(String message, Throwable cause) { | 24 | + public Bmv2InterpreterException(String message) { |
25 | - super(message, cause); | ||
26 | - } | ||
27 | - | ||
28 | - public Bmv2RuntimeException(String message) { | ||
29 | super(message); | 25 | super(message); |
30 | } | 26 | } |
31 | } | 27 | } | ... | ... |
... | @@ -14,27 +14,30 @@ | ... | @@ -14,27 +14,30 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
18 | + | ||
19 | +import com.google.common.annotations.Beta; | ||
18 | 20 | ||
19 | import java.util.Objects; | 21 | import java.util.Objects; |
20 | 22 | ||
21 | import static com.google.common.base.MoreObjects.toStringHelper; | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
22 | 24 | ||
23 | /** | 25 | /** |
24 | - * BMv2 model action runtime data. | 26 | + * A BMv2 action runtime data model. |
25 | */ | 27 | */ |
26 | -public final class Bmv2ModelRuntimeData { | 28 | +@Beta |
29 | +public final class Bmv2RuntimeDataModel { | ||
27 | 30 | ||
28 | private final String name; | 31 | private final String name; |
29 | private final int bitWidth; | 32 | private final int bitWidth; |
30 | 33 | ||
31 | /** | 34 | /** |
32 | - * Creates a new runtime data. | 35 | + * Creates a new runtime data model. |
33 | * | 36 | * |
34 | * @param name name | 37 | * @param name name |
35 | * @param bitWidth bitwidth | 38 | * @param bitWidth bitwidth |
36 | */ | 39 | */ |
37 | - protected Bmv2ModelRuntimeData(String name, int bitWidth) { | 40 | + protected Bmv2RuntimeDataModel(String name, int bitWidth) { |
38 | this.name = name; | 41 | this.name = name; |
39 | this.bitWidth = bitWidth; | 42 | this.bitWidth = bitWidth; |
40 | } | 43 | } |
... | @@ -70,7 +73,7 @@ public final class Bmv2ModelRuntimeData { | ... | @@ -70,7 +73,7 @@ public final class Bmv2ModelRuntimeData { |
70 | if (obj == null || getClass() != obj.getClass()) { | 73 | if (obj == null || getClass() != obj.getClass()) { |
71 | return false; | 74 | return false; |
72 | } | 75 | } |
73 | - final Bmv2ModelRuntimeData other = (Bmv2ModelRuntimeData) obj; | 76 | + final Bmv2RuntimeDataModel other = (Bmv2RuntimeDataModel) obj; |
74 | return Objects.equals(this.name, other.name) | 77 | return Objects.equals(this.name, other.name) |
75 | && Objects.equals(this.bitWidth, other.bitWidth); | 78 | && Objects.equals(this.bitWidth, other.bitWidth); |
76 | } | 79 | } | ... | ... |
... | @@ -14,28 +14,30 @@ | ... | @@ -14,28 +14,30 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
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.bmv2.api.runtime.Bmv2MatchParam; | 21 | import org.onosproject.bmv2.api.runtime.Bmv2MatchParam; |
21 | 22 | ||
22 | import static com.google.common.base.MoreObjects.toStringHelper; | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
23 | 24 | ||
24 | /** | 25 | /** |
25 | - * Representation of a table key. | 26 | + * A BMv2 table key model. |
26 | */ | 27 | */ |
27 | -public final class Bmv2ModelTableKey { | 28 | +@Beta |
29 | +public final class Bmv2TableKeyModel { | ||
28 | 30 | ||
29 | private final Bmv2MatchParam.Type matchType; | 31 | private final Bmv2MatchParam.Type matchType; |
30 | - private final Bmv2ModelField field; | 32 | + private final Bmv2FieldModel field; |
31 | 33 | ||
32 | /** | 34 | /** |
33 | - * Creates a new table key. | 35 | + * Creates a new table key model. |
34 | * | 36 | * |
35 | * @param matchType match type | 37 | * @param matchType match type |
36 | * @param field field instance | 38 | * @param field field instance |
37 | */ | 39 | */ |
38 | - protected Bmv2ModelTableKey(Bmv2MatchParam.Type matchType, Bmv2ModelField field) { | 40 | + protected Bmv2TableKeyModel(Bmv2MatchParam.Type matchType, Bmv2FieldModel field) { |
39 | this.matchType = matchType; | 41 | this.matchType = matchType; |
40 | this.field = field; | 42 | this.field = field; |
41 | } | 43 | } |
... | @@ -55,7 +57,7 @@ public final class Bmv2ModelTableKey { | ... | @@ -55,7 +57,7 @@ public final class Bmv2ModelTableKey { |
55 | * | 57 | * |
56 | * @return a header field value | 58 | * @return a header field value |
57 | */ | 59 | */ |
58 | - public Bmv2ModelField field() { | 60 | + public Bmv2FieldModel field() { |
59 | return field; | 61 | return field; |
60 | } | 62 | } |
61 | 63 | ||
... | @@ -72,7 +74,7 @@ public final class Bmv2ModelTableKey { | ... | @@ -72,7 +74,7 @@ public final class Bmv2ModelTableKey { |
72 | if (obj == null || getClass() != obj.getClass()) { | 74 | if (obj == null || getClass() != obj.getClass()) { |
73 | return false; | 75 | return false; |
74 | } | 76 | } |
75 | - final Bmv2ModelTableKey other = (Bmv2ModelTableKey) obj; | 77 | + final Bmv2TableKeyModel other = (Bmv2TableKeyModel) obj; |
76 | return Objects.equal(this.matchType, other.matchType) | 78 | return Objects.equal(this.matchType, other.matchType) |
77 | && Objects.equal(this.field, other.field); | 79 | && Objects.equal(this.field, other.field); |
78 | } | 80 | } | ... | ... |
... | @@ -14,8 +14,9 @@ | ... | @@ -14,8 +14,9 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
18 | 18 | ||
19 | +import com.google.common.annotations.Beta; | ||
19 | import com.google.common.base.Objects; | 20 | import com.google.common.base.Objects; |
20 | 21 | ||
21 | import java.util.List; | 22 | import java.util.List; |
... | @@ -24,9 +25,10 @@ import java.util.Set; | ... | @@ -24,9 +25,10 @@ import java.util.Set; |
24 | import static com.google.common.base.MoreObjects.toStringHelper; | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
25 | 26 | ||
26 | /** | 27 | /** |
27 | - * BMv2 model table representation. | 28 | + * A BMv2 table model. |
28 | */ | 29 | */ |
29 | -public final class Bmv2ModelTable { | 30 | +@Beta |
31 | +public final class Bmv2TableModel { | ||
30 | 32 | ||
31 | private final String name; | 33 | private final String name; |
32 | private final int id; | 34 | private final int id; |
... | @@ -35,11 +37,11 @@ public final class Bmv2ModelTable { | ... | @@ -35,11 +37,11 @@ public final class Bmv2ModelTable { |
35 | private final int maxSize; | 37 | private final int maxSize; |
36 | private final boolean hasCounters; | 38 | private final boolean hasCounters; |
37 | private final boolean hasTimeouts; | 39 | private final boolean hasTimeouts; |
38 | - private final List<Bmv2ModelTableKey> keys; | 40 | + private final List<Bmv2TableKeyModel> keys; |
39 | - private final Set<Bmv2ModelAction> actions; | 41 | + private final Set<Bmv2ActionModel> actions; |
40 | 42 | ||
41 | /** | 43 | /** |
42 | - * Creates a new table. | 44 | + * Creates a new table model. |
43 | * | 45 | * |
44 | * @param name name | 46 | * @param name name |
45 | * @param id id | 47 | * @param id id |
... | @@ -51,9 +53,9 @@ public final class Bmv2ModelTable { | ... | @@ -51,9 +53,9 @@ public final class Bmv2ModelTable { |
51 | * @param keys list of match keys | 53 | * @param keys list of match keys |
52 | * @param actions list of actions | 54 | * @param actions list of actions |
53 | */ | 55 | */ |
54 | - protected Bmv2ModelTable(String name, int id, String matchType, String type, | 56 | + protected Bmv2TableModel(String name, int id, String matchType, String type, |
55 | int maxSize, boolean withCounters, boolean supportTimeout, | 57 | int maxSize, boolean withCounters, boolean supportTimeout, |
56 | - List<Bmv2ModelTableKey> keys, Set<Bmv2ModelAction> actions) { | 58 | + List<Bmv2TableKeyModel> keys, Set<Bmv2ActionModel> actions) { |
57 | this.name = name; | 59 | this.name = name; |
58 | this.id = id; | 60 | this.id = id; |
59 | this.matchType = matchType; | 61 | this.matchType = matchType; |
... | @@ -134,7 +136,7 @@ public final class Bmv2ModelTable { | ... | @@ -134,7 +136,7 @@ public final class Bmv2ModelTable { |
134 | * | 136 | * |
135 | * @return a list of match keys | 137 | * @return a list of match keys |
136 | */ | 138 | */ |
137 | - public List<Bmv2ModelTableKey> keys() { | 139 | + public List<Bmv2TableKeyModel> keys() { |
138 | return keys; | 140 | return keys; |
139 | } | 141 | } |
140 | 142 | ||
... | @@ -143,7 +145,7 @@ public final class Bmv2ModelTable { | ... | @@ -143,7 +145,7 @@ public final class Bmv2ModelTable { |
143 | * | 145 | * |
144 | * @return a list of actions | 146 | * @return a list of actions |
145 | */ | 147 | */ |
146 | - public Set<Bmv2ModelAction> actions() { | 148 | + public Set<Bmv2ActionModel> actions() { |
147 | return actions; | 149 | return actions; |
148 | } | 150 | } |
149 | 151 | ||
... | @@ -161,7 +163,7 @@ public final class Bmv2ModelTable { | ... | @@ -161,7 +163,7 @@ public final class Bmv2ModelTable { |
161 | if (obj == null || getClass() != obj.getClass()) { | 163 | if (obj == null || getClass() != obj.getClass()) { |
162 | return false; | 164 | return false; |
163 | } | 165 | } |
164 | - final Bmv2ModelTable other = (Bmv2ModelTable) obj; | 166 | + final Bmv2TableModel other = (Bmv2TableModel) obj; |
165 | return Objects.equal(this.name, other.name) | 167 | return Objects.equal(this.name, other.name) |
166 | && Objects.equal(this.id, other.id) | 168 | && Objects.equal(this.id, other.id) |
167 | && Objects.equal(this.matchType, other.matchType) | 169 | && Objects.equal(this.matchType, other.matchType) | ... | ... |
... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /** | 17 | /** |
18 | - * BMv2 configuration model classes. | 18 | + * BMv2 device context API. |
19 | */ | 19 | */ |
20 | -package org.onosproject.bmv2.api.model; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
20 | +package org.onosproject.bmv2.api.context; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -15,11 +15,6 @@ | ... | @@ -15,11 +15,6 @@ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /** | 17 | /** |
18 | - * Bmv2 API abstractions. | 18 | + * BMv2 protocol API. |
19 | - * <p> | ||
20 | - * Bmv2 APIs are divided in two sub-packages, runtime and model. | ||
21 | - * Runtime APIs are used to represent operations that can be performed at runtime | ||
22 | - * on a Bmv2 device, while model APIs are used to describe the Bmv2 packet | ||
23 | - * processing model. | ||
24 | */ | 19 | */ |
25 | package org.onosproject.bmv2.api; | 20 | package org.onosproject.bmv2.api; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull; |
28 | import static com.google.common.base.Preconditions.checkState; | 28 | import static com.google.common.base.Preconditions.checkState; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | - * Bmv2 action representation. | 31 | + * An action of a BMv2 match-action table entry. |
32 | */ | 32 | */ |
33 | public final class Bmv2Action { | 33 | public final class Bmv2Action { |
34 | 34 | ||
... | @@ -94,7 +94,7 @@ public final class Bmv2Action { | ... | @@ -94,7 +94,7 @@ public final class Bmv2Action { |
94 | } | 94 | } |
95 | 95 | ||
96 | /** | 96 | /** |
97 | - * A Bmv2 action builder. | 97 | + * A BMv2 action builder. |
98 | */ | 98 | */ |
99 | public static final class Builder { | 99 | public static final class Builder { |
100 | 100 | ||
... | @@ -128,9 +128,9 @@ public final class Bmv2Action { | ... | @@ -128,9 +128,9 @@ public final class Bmv2Action { |
128 | } | 128 | } |
129 | 129 | ||
130 | /** | 130 | /** |
131 | - * Builds a Bmv2 action object. | 131 | + * Builds a BMv2 action object. |
132 | * | 132 | * |
133 | - * @return a Bmv2 action | 133 | + * @return a BMv2 action |
134 | */ | 134 | */ |
135 | public Bmv2Action build() { | 135 | public Bmv2Action build() { |
136 | checkState(name != null, "action name not set"); | 136 | checkState(name != null, "action name not set"); | ... | ... |
... | @@ -21,6 +21,8 @@ import org.onosproject.net.DeviceId; | ... | @@ -21,6 +21,8 @@ import org.onosproject.net.DeviceId; |
21 | 21 | ||
22 | import java.net.URI; | 22 | import java.net.URI; |
23 | import java.net.URISyntaxException; | 23 | import java.net.URISyntaxException; |
24 | +import java.util.regex.Matcher; | ||
25 | +import java.util.regex.Pattern; | ||
24 | 26 | ||
25 | import static com.google.common.base.Preconditions.checkNotNull; | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
26 | 28 | ||
... | @@ -29,20 +31,25 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -29,20 +31,25 @@ import static com.google.common.base.Preconditions.checkNotNull; |
29 | */ | 31 | */ |
30 | public final class Bmv2Device { | 32 | public final class Bmv2Device { |
31 | 33 | ||
34 | + public static final String N_A = "n/a"; | ||
35 | + | ||
32 | public static final String SCHEME = "bmv2"; | 36 | public static final String SCHEME = "bmv2"; |
37 | + public static final String PROTOCOL = "bmv2-thrift"; | ||
33 | public static final String MANUFACTURER = "p4.org"; | 38 | public static final String MANUFACTURER = "p4.org"; |
34 | public static final String HW_VERSION = "bmv2"; | 39 | public static final String HW_VERSION = "bmv2"; |
40 | + public static final String SW_VERSION = N_A; | ||
41 | + public static final String SERIAL_NUMBER = N_A; | ||
35 | 42 | ||
36 | private final String thriftServerHost; | 43 | private final String thriftServerHost; |
37 | private final int thriftServerPort; | 44 | private final int thriftServerPort; |
38 | private final int internalDeviceId; | 45 | private final int internalDeviceId; |
39 | 46 | ||
40 | /** | 47 | /** |
41 | - * Creates a new Bmv2 device object. | 48 | + * Creates a new BMv2 device object. |
42 | * | 49 | * |
43 | - * @param thriftServerHost the host of the Thrift runtime server running inside the device | 50 | + * @param thriftServerHost the hostname / IP address of the Thrift runtime server running on the device |
44 | - * @param thriftServerPort the port of the Thrift runtime server running inside the device | 51 | + * @param thriftServerPort the port of the Thrift runtime server running on the device |
45 | - * @param internalDeviceId the internal device id | 52 | + * @param internalDeviceId the internal device ID number |
46 | */ | 53 | */ |
47 | public Bmv2Device(String thriftServerHost, int thriftServerPort, int internalDeviceId) { | 54 | public Bmv2Device(String thriftServerHost, int thriftServerPort, int internalDeviceId) { |
48 | this.thriftServerHost = checkNotNull(thriftServerHost, "host cannot be null"); | 55 | this.thriftServerHost = checkNotNull(thriftServerHost, "host cannot be null"); |
... | @@ -51,7 +58,17 @@ public final class Bmv2Device { | ... | @@ -51,7 +58,17 @@ public final class Bmv2Device { |
51 | } | 58 | } |
52 | 59 | ||
53 | /** | 60 | /** |
54 | - * Returns the hostname (or IP address) of the Thrift runtime server running inside the device. | 61 | + * Returns a Bmv2Device representing the given deviceId. |
62 | + * | ||
63 | + * @param deviceId a deviceId | ||
64 | + * @return | ||
65 | + */ | ||
66 | + public static Bmv2Device of(DeviceId deviceId) { | ||
67 | + return DeviceIdParser.parse(checkNotNull(deviceId, "deviceId cannot be null")); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Returns the hostname (or IP address) of the Thrift runtime server running on the device. | ||
55 | * | 72 | * |
56 | * @return a string value | 73 | * @return a string value |
57 | */ | 74 | */ |
... | @@ -60,7 +77,7 @@ public final class Bmv2Device { | ... | @@ -60,7 +77,7 @@ public final class Bmv2Device { |
60 | } | 77 | } |
61 | 78 | ||
62 | /** | 79 | /** |
63 | - * Returns the port of the Thrift runtime server running inside the device. | 80 | + * Returns the port of the Thrift runtime server running on the device. |
64 | * | 81 | * |
65 | * @return an integer value | 82 | * @return an integer value |
66 | */ | 83 | */ |
... | @@ -86,7 +103,8 @@ public final class Bmv2Device { | ... | @@ -86,7 +103,8 @@ public final class Bmv2Device { |
86 | public DeviceId asDeviceId() { | 103 | public DeviceId asDeviceId() { |
87 | try { | 104 | try { |
88 | // TODO: include internalDeviceId number in the deviceId URI | 105 | // TODO: include internalDeviceId number in the deviceId URI |
89 | - return DeviceId.deviceId(new URI(SCHEME, this.thriftServerHost + ":" + this.thriftServerPort, null)); | 106 | + return DeviceId.deviceId(new URI(SCHEME, this.thriftServerHost + ":" + this.thriftServerPort, |
107 | + String.valueOf(this.internalDeviceId))); | ||
90 | } catch (URISyntaxException e) { | 108 | } catch (URISyntaxException e) { |
91 | throw new IllegalArgumentException("Unable to build deviceID for device " + this.toString(), e); | 109 | throw new IllegalArgumentException("Unable to build deviceID for device " + this.toString(), e); |
92 | } | 110 | } |
... | @@ -113,6 +131,23 @@ public final class Bmv2Device { | ... | @@ -113,6 +131,23 @@ public final class Bmv2Device { |
113 | 131 | ||
114 | @Override | 132 | @Override |
115 | public String toString() { | 133 | public String toString() { |
116 | - return thriftServerHost + ":" + thriftServerPort + "/" + internalDeviceId; | 134 | + return asDeviceId().toString(); |
135 | + } | ||
136 | + | ||
137 | + private static class DeviceIdParser { | ||
138 | + | ||
139 | + private static final Pattern REGEX = Pattern.compile(SCHEME + ":(.+):(\\d+)#(\\d+)"); | ||
140 | + | ||
141 | + public static Bmv2Device parse(DeviceId deviceId) { | ||
142 | + Matcher matcher = REGEX.matcher(deviceId.toString()); | ||
143 | + if (matcher.find()) { | ||
144 | + String host = matcher.group(1); | ||
145 | + int port = Integer.valueOf(matcher.group(2)); | ||
146 | + int internalDeviceId = Integer.valueOf(matcher.group(3)); | ||
147 | + return new Bmv2Device(host, port, internalDeviceId); | ||
148 | + } else { | ||
149 | + throw new RuntimeException("Unable to parse bmv2 device id string: " + deviceId.toString()); | ||
150 | + } | ||
151 | + } | ||
117 | } | 152 | } |
118 | } | 153 | } | ... | ... |
... | @@ -18,14 +18,29 @@ package org.onosproject.bmv2.api.runtime; | ... | @@ -18,14 +18,29 @@ package org.onosproject.bmv2.api.runtime; |
18 | 18 | ||
19 | import org.apache.commons.lang3.tuple.Pair; | 19 | import org.apache.commons.lang3.tuple.Pair; |
20 | import org.onlab.util.ImmutableByteSequence; | 20 | import org.onlab.util.ImmutableByteSequence; |
21 | +import org.onosproject.net.DeviceId; | ||
21 | 22 | ||
22 | import java.util.Collection; | 23 | import java.util.Collection; |
23 | -import java.util.List; | ||
24 | 24 | ||
25 | /** | 25 | /** |
26 | - * RPC client to control a BMv2 device. | 26 | + * An agent to control a BMv2 device. |
27 | */ | 27 | */ |
28 | -public interface Bmv2Client { | 28 | +public interface Bmv2DeviceAgent { |
29 | + | ||
30 | + /** | ||
31 | + * Returns the device ID of this agent. | ||
32 | + * | ||
33 | + * @return a device id | ||
34 | + */ | ||
35 | + DeviceId deviceId(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Pings the device, returns true if the device is reachable, false otherwise. | ||
39 | + * | ||
40 | + * @return true if reachable, false otherwise | ||
41 | + */ | ||
42 | + boolean ping(); | ||
43 | + | ||
29 | /** | 44 | /** |
30 | * Adds a new table entry. | 45 | * Adds a new table entry. |
31 | * | 46 | * |
... | @@ -36,16 +51,14 @@ public interface Bmv2Client { | ... | @@ -36,16 +51,14 @@ public interface Bmv2Client { |
36 | long addTableEntry(Bmv2TableEntry entry) throws Bmv2RuntimeException; | 51 | long addTableEntry(Bmv2TableEntry entry) throws Bmv2RuntimeException; |
37 | 52 | ||
38 | /** | 53 | /** |
39 | - * Modifies a currently installed entry by updating its action. | 54 | + * Modifies an existing table entry by updating its action. |
40 | * | 55 | * |
41 | * @param tableName string value of table name | 56 | * @param tableName string value of table name |
42 | * @param entryId long value of entry ID | 57 | * @param entryId long value of entry ID |
43 | * @param action an action value | 58 | * @param action an action value |
44 | * @throws Bmv2RuntimeException if any error occurs | 59 | * @throws Bmv2RuntimeException if any error occurs |
45 | */ | 60 | */ |
46 | - void modifyTableEntry(String tableName, | 61 | + void modifyTableEntry(String tableName, long entryId, Bmv2Action action) throws Bmv2RuntimeException; |
47 | - long entryId, Bmv2Action action) | ||
48 | - throws Bmv2RuntimeException; | ||
49 | 62 | ||
50 | /** | 63 | /** |
51 | * Deletes currently installed entry. | 64 | * Deletes currently installed entry. |
... | @@ -54,8 +67,7 @@ public interface Bmv2Client { | ... | @@ -54,8 +67,7 @@ public interface Bmv2Client { |
54 | * @param entryId long value of entry ID | 67 | * @param entryId long value of entry ID |
55 | * @throws Bmv2RuntimeException if any error occurs | 68 | * @throws Bmv2RuntimeException if any error occurs |
56 | */ | 69 | */ |
57 | - void deleteTableEntry(String tableName, | 70 | + void deleteTableEntry(String tableName, long entryId) throws Bmv2RuntimeException; |
58 | - long entryId) throws Bmv2RuntimeException; | ||
59 | 71 | ||
60 | /** | 72 | /** |
61 | * Sets table default action. | 73 | * Sets table default action. |
... | @@ -64,11 +76,10 @@ public interface Bmv2Client { | ... | @@ -64,11 +76,10 @@ public interface Bmv2Client { |
64 | * @param action an action value | 76 | * @param action an action value |
65 | * @throws Bmv2RuntimeException if any error occurs | 77 | * @throws Bmv2RuntimeException if any error occurs |
66 | */ | 78 | */ |
67 | - void setTableDefaultAction(String tableName, Bmv2Action action) | 79 | + void setTableDefaultAction(String tableName, Bmv2Action action) throws Bmv2RuntimeException; |
68 | - throws Bmv2RuntimeException; | ||
69 | 80 | ||
70 | /** | 81 | /** |
71 | - * Returns information of the ports currently configured in the switch. | 82 | + * Returns information on the ports currently configured in the switch. |
72 | * | 83 | * |
73 | * @return collection of port information | 84 | * @return collection of port information |
74 | * @throws Bmv2RuntimeException if any error occurs | 85 | * @throws Bmv2RuntimeException if any error occurs |
... | @@ -76,7 +87,7 @@ public interface Bmv2Client { | ... | @@ -76,7 +87,7 @@ public interface Bmv2Client { |
76 | Collection<Bmv2PortInfo> getPortsInfo() throws Bmv2RuntimeException; | 87 | Collection<Bmv2PortInfo> getPortsInfo() throws Bmv2RuntimeException; |
77 | 88 | ||
78 | /** | 89 | /** |
79 | - * Return a string representation of a table content. | 90 | + * Return a string representation of the given table content. |
80 | * | 91 | * |
81 | * @param tableName string value of table name | 92 | * @param tableName string value of table name |
82 | * @return table string dump | 93 | * @return table string dump |
... | @@ -85,24 +96,6 @@ public interface Bmv2Client { | ... | @@ -85,24 +96,6 @@ public interface Bmv2Client { |
85 | String dumpTable(String tableName) throws Bmv2RuntimeException; | 96 | String dumpTable(String tableName) throws Bmv2RuntimeException; |
86 | 97 | ||
87 | /** | 98 | /** |
88 | - * Returns a list of ids for the entries installed in the given table. | ||
89 | - * | ||
90 | - * @param tableName string value of table name | ||
91 | - * @return a list of entry ids | ||
92 | - * @throws Bmv2RuntimeException if any error occurs | ||
93 | - */ | ||
94 | - List<Long> getInstalledEntryIds(String tableName) throws Bmv2RuntimeException; | ||
95 | - | ||
96 | - /** | ||
97 | - * Removes all entries installed in the given table. | ||
98 | - * | ||
99 | - * @param tableName string value of table name | ||
100 | - * @return the number of entries removed | ||
101 | - * @throws Bmv2RuntimeException if any error occurs | ||
102 | - */ | ||
103 | - int cleanupTable(String tableName) throws Bmv2RuntimeException; | ||
104 | - | ||
105 | - /** | ||
106 | * Requests the device to transmit a given byte sequence over the given port. | 99 | * Requests the device to transmit a given byte sequence over the given port. |
107 | * | 100 | * |
108 | * @param portNumber a port number | 101 | * @param portNumber a port number |
... | @@ -112,14 +105,14 @@ public interface Bmv2Client { | ... | @@ -112,14 +105,14 @@ public interface Bmv2Client { |
112 | void transmitPacket(int portNumber, ImmutableByteSequence packet) throws Bmv2RuntimeException; | 105 | void transmitPacket(int portNumber, ImmutableByteSequence packet) throws Bmv2RuntimeException; |
113 | 106 | ||
114 | /** | 107 | /** |
115 | - * Reset the state of the switch (e.g. delete all entries, etc.). | 108 | + * Resets the state of the switch (e.g. delete all entries, etc.). |
116 | * | 109 | * |
117 | * @throws Bmv2RuntimeException if any error occurs | 110 | * @throws Bmv2RuntimeException if any error occurs |
118 | */ | 111 | */ |
119 | void resetState() throws Bmv2RuntimeException; | 112 | void resetState() throws Bmv2RuntimeException; |
120 | 113 | ||
121 | /** | 114 | /** |
122 | - * Returns the JSON-formatted model configuration currently used to process packets. | 115 | + * Returns the JSON configuration currently used to process packets. |
123 | * | 116 | * |
124 | * @return a JSON-formatted string value | 117 | * @return a JSON-formatted string value |
125 | * @throws Bmv2RuntimeException if any error occurs | 118 | * @throws Bmv2RuntimeException if any error occurs |
... | @@ -127,7 +120,7 @@ public interface Bmv2Client { | ... | @@ -127,7 +120,7 @@ public interface Bmv2Client { |
127 | String dumpJsonConfig() throws Bmv2RuntimeException; | 120 | String dumpJsonConfig() throws Bmv2RuntimeException; |
128 | 121 | ||
129 | /** | 122 | /** |
130 | - * Returns the md5 hash of the JSON-formatted model configuration currently used to process packets. | 123 | + * Returns the md5 sum of the JSON-formatted model configuration currently used to process packets. |
131 | * | 124 | * |
132 | * @return a string value | 125 | * @return a string value |
133 | * @throws Bmv2RuntimeException if any error occurs | 126 | * @throws Bmv2RuntimeException if any error occurs |
... | @@ -143,4 +136,39 @@ public interface Bmv2Client { | ... | @@ -143,4 +136,39 @@ public interface Bmv2Client { |
143 | * @throws Bmv2RuntimeException if any error occurs | 136 | * @throws Bmv2RuntimeException if any error occurs |
144 | */ | 137 | */ |
145 | Pair<Long, Long> readTableEntryCounter(String tableName, long entryId) throws Bmv2RuntimeException; | 138 | Pair<Long, Long> readTableEntryCounter(String tableName, long entryId) throws Bmv2RuntimeException; |
139 | + | ||
140 | + /** | ||
141 | + * Returns the counter values for a given counter and index. | ||
142 | + * | ||
143 | + * @param counterName a counter name | ||
144 | + * @param index an integer value | ||
145 | + * @return a pair of long values, where the left value is the number of bytes and the right value is the number of | ||
146 | + * packets | ||
147 | + * @throws Bmv2RuntimeException if any error occurs | ||
148 | + */ | ||
149 | + Pair<Long, Long> readCounter(String counterName, int index) throws Bmv2RuntimeException; | ||
150 | + | ||
151 | + /** | ||
152 | + * Returns the ID of the current BMv2 process instance (used to distinguish between different executions of the | ||
153 | + * same BMv2 device). | ||
154 | + * | ||
155 | + * @return an integer value | ||
156 | + * @throws Bmv2RuntimeException if any error occurs | ||
157 | + */ | ||
158 | + int getProcessInstanceId() throws Bmv2RuntimeException; | ||
159 | + | ||
160 | + /** | ||
161 | + * Uploads a new JSON configuration on the device. | ||
162 | + * | ||
163 | + * @param jsonString a string value | ||
164 | + * @throws Bmv2RuntimeException if any error occurs | ||
165 | + */ | ||
166 | + void loadNewJsonConfig(String jsonString) throws Bmv2RuntimeException; | ||
167 | + | ||
168 | + /** | ||
169 | + * Triggers a configuration swap on the device. | ||
170 | + * | ||
171 | + * @throws Bmv2RuntimeException | ||
172 | + */ | ||
173 | + void swapJsonConfig() throws Bmv2RuntimeException; | ||
146 | } | 174 | } | ... | ... |
... | @@ -23,9 +23,9 @@ import org.onlab.util.ImmutableByteSequence; | ... | @@ -23,9 +23,9 @@ import org.onlab.util.ImmutableByteSequence; |
23 | import static com.google.common.base.Preconditions.checkNotNull; | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | - * Representation of a Bmv2 exact match parameter. | 26 | + * Representation of a BMv2 exact match parameter. |
27 | */ | 27 | */ |
28 | -public class Bmv2ExactMatchParam implements Bmv2MatchParam { | 28 | +public final class Bmv2ExactMatchParam implements Bmv2MatchParam { |
29 | 29 | ||
30 | private final ImmutableByteSequence value; | 30 | private final ImmutableByteSequence value; |
31 | 31 | ... | ... |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2ExtensionSelector.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.runtime; | ||
18 | + | ||
19 | +import com.google.common.base.MoreObjects; | ||
20 | +import com.google.common.base.Objects; | ||
21 | +import org.onlab.util.KryoNamespace; | ||
22 | +import org.onosproject.net.flow.AbstractExtension; | ||
23 | +import org.onosproject.net.flow.criteria.ExtensionSelector; | ||
24 | +import org.onosproject.net.flow.criteria.ExtensionSelectorType; | ||
25 | + | ||
26 | +import java.util.HashMap; | ||
27 | +import java.util.Map; | ||
28 | + | ||
29 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
30 | + | ||
31 | +/** | ||
32 | + * Extension selector for BMv2 used as a wrapper for multiple BMv2 match parameters. | ||
33 | + */ | ||
34 | +public final class Bmv2ExtensionSelector extends AbstractExtension implements ExtensionSelector { | ||
35 | + | ||
36 | + private final KryoNamespace appKryo = new KryoNamespace.Builder() | ||
37 | + .register(HashMap.class) | ||
38 | + .register(Bmv2MatchParam.class) | ||
39 | + .register(Bmv2ExactMatchParam.class) | ||
40 | + .register(Bmv2TernaryMatchParam.class) | ||
41 | + .register(Bmv2LpmMatchParam.class) | ||
42 | + .register(Bmv2ValidMatchParam.class) | ||
43 | + .build(); | ||
44 | + | ||
45 | + private Map<String, Bmv2MatchParam> parameterMap; | ||
46 | + | ||
47 | + /** | ||
48 | + * Creates a new BMv2 extension selector for the given match parameters map, where the keys are expected to be field | ||
49 | + * names formatted as headerName.fieldMemberName (e.g. ethernet.dstAddr). | ||
50 | + * | ||
51 | + * @param paramMap a map | ||
52 | + */ | ||
53 | + public Bmv2ExtensionSelector(Map<String, Bmv2MatchParam> paramMap) { | ||
54 | + this.parameterMap = checkNotNull(paramMap, "param map cannot be null"); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the match parameters map of this selector. | ||
59 | + * | ||
60 | + * @return a match parameter map | ||
61 | + */ | ||
62 | + public Map<String, Bmv2MatchParam> parameterMap() { | ||
63 | + return parameterMap; | ||
64 | + } | ||
65 | + | ||
66 | + | ||
67 | + @Override | ||
68 | + public ExtensionSelectorType type() { | ||
69 | + return ExtensionSelectorType.ExtensionSelectorTypes.BMV2_MATCH_PARAMS.type(); | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public byte[] serialize() { | ||
74 | + return appKryo.serialize(parameterMap); | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public void deserialize(byte[] data) { | ||
79 | + this.parameterMap = appKryo.deserialize(data); | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public int hashCode() { | ||
84 | + return Objects.hashCode(parameterMap); | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public boolean equals(Object obj) { | ||
89 | + if (this == obj) { | ||
90 | + return true; | ||
91 | + } | ||
92 | + if (obj == null || getClass() != obj.getClass()) { | ||
93 | + return false; | ||
94 | + } | ||
95 | + final Bmv2ExtensionSelector other = (Bmv2ExtensionSelector) obj; | ||
96 | + return Objects.equal(this.parameterMap, other.parameterMap); | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public String toString() { | ||
101 | + return MoreObjects.toStringHelper(this) | ||
102 | + .add("parameterMap", parameterMap) | ||
103 | + .toString(); | ||
104 | + } | ||
105 | +} |
... | @@ -16,15 +16,19 @@ | ... | @@ -16,15 +16,19 @@ |
16 | 16 | ||
17 | package org.onosproject.bmv2.api.runtime; | 17 | package org.onosproject.bmv2.api.runtime; |
18 | 18 | ||
19 | +import com.google.common.base.MoreObjects; | ||
20 | +import com.google.common.base.Objects; | ||
19 | import org.onlab.util.KryoNamespace; | 21 | import org.onlab.util.KryoNamespace; |
20 | import org.onosproject.net.flow.AbstractExtension; | 22 | import org.onosproject.net.flow.AbstractExtension; |
21 | import org.onosproject.net.flow.instructions.ExtensionTreatment; | 23 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
22 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; | 24 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
23 | 25 | ||
26 | +import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.BMV2_ACTION; | ||
27 | + | ||
24 | /** | 28 | /** |
25 | - * Extension treatment for Bmv2 used as a wrapper for a {@link Bmv2Action}. | 29 | + * Extension treatment for BMv2 used as a wrapper for a {@link Bmv2Action}. |
26 | */ | 30 | */ |
27 | -public class Bmv2ExtensionTreatment extends AbstractExtension implements ExtensionTreatment { | 31 | +public final class Bmv2ExtensionTreatment extends AbstractExtension implements ExtensionTreatment { |
28 | 32 | ||
29 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); | 33 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); |
30 | private Bmv2Action action; | 34 | private Bmv2Action action; |
... | @@ -39,7 +43,7 @@ public class Bmv2ExtensionTreatment extends AbstractExtension implements Extensi | ... | @@ -39,7 +43,7 @@ public class Bmv2ExtensionTreatment extends AbstractExtension implements Extensi |
39 | 43 | ||
40 | @Override | 44 | @Override |
41 | public ExtensionTreatmentType type() { | 45 | public ExtensionTreatmentType type() { |
42 | - return ExtensionTreatmentType.ExtensionTreatmentTypes.P4_BMV2_ACTION.type(); | 46 | + return BMV2_ACTION.type(); |
43 | } | 47 | } |
44 | 48 | ||
45 | @Override | 49 | @Override |
... | @@ -51,4 +55,28 @@ public class Bmv2ExtensionTreatment extends AbstractExtension implements Extensi | ... | @@ -51,4 +55,28 @@ public class Bmv2ExtensionTreatment extends AbstractExtension implements Extensi |
51 | public void deserialize(byte[] data) { | 55 | public void deserialize(byte[] data) { |
52 | action = appKryo.deserialize(data); | 56 | action = appKryo.deserialize(data); |
53 | } | 57 | } |
58 | + | ||
59 | + @Override | ||
60 | + public int hashCode() { | ||
61 | + return Objects.hashCode(action); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public boolean equals(Object obj) { | ||
66 | + if (this == obj) { | ||
67 | + return true; | ||
68 | + } | ||
69 | + if (obj == null || getClass() != obj.getClass()) { | ||
70 | + return false; | ||
71 | + } | ||
72 | + final Bmv2ExtensionTreatment other = (Bmv2ExtensionTreatment) obj; | ||
73 | + return Objects.equal(this.action, other.action); | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public String toString() { | ||
78 | + return MoreObjects.toStringHelper(this) | ||
79 | + .add("action", action) | ||
80 | + .toString(); | ||
81 | + } | ||
54 | } | 82 | } | ... | ... |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2FlowRuleWrapper.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.runtime; | ||
18 | + | ||
19 | +import com.google.common.base.Objects; | ||
20 | +import org.onosproject.net.flow.FlowRule; | ||
21 | + | ||
22 | +import java.util.Date; | ||
23 | + | ||
24 | +/** | ||
25 | + * A wrapper class for a ONOS flow rule installed on a BMv2 device. | ||
26 | + */ | ||
27 | +public class Bmv2FlowRuleWrapper { | ||
28 | + | ||
29 | + private final FlowRule rule; | ||
30 | + private final long entryId; | ||
31 | + private final Date creationDate; | ||
32 | + | ||
33 | + /** | ||
34 | + * Creates a new flow rule wrapper. | ||
35 | + * | ||
36 | + * @param rule a flow rule | ||
37 | + * @param entryId a BMv2 table entry ID | ||
38 | + * @param creationDate the creation date of the flow rule | ||
39 | + */ | ||
40 | + public Bmv2FlowRuleWrapper(FlowRule rule, long entryId, Date creationDate) { | ||
41 | + this.rule = rule; | ||
42 | + this.entryId = entryId; | ||
43 | + this.creationDate = new Date(); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the flow rule contained by this wrapper. | ||
48 | + * | ||
49 | + * @return a flow rule | ||
50 | + */ | ||
51 | + public FlowRule rule() { | ||
52 | + return rule; | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Return the seconds since when this flow rule was installed on the device. | ||
57 | + * | ||
58 | + * @return an integer value | ||
59 | + */ | ||
60 | + public long lifeInSeconds() { | ||
61 | + return (new Date().getTime() - creationDate.getTime()) / 1000; | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Returns the creation date of this flow rule. | ||
66 | + * | ||
67 | + * @return a date | ||
68 | + */ | ||
69 | + public Date creationDate() { | ||
70 | + return creationDate; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Returns the BMv2 entry ID of this flow rule. | ||
75 | + * | ||
76 | + * @return a long value | ||
77 | + */ | ||
78 | + public long entryId() { | ||
79 | + return entryId; | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public int hashCode() { | ||
84 | + return Objects.hashCode(rule, entryId, creationDate); | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public boolean equals(Object obj) { | ||
89 | + if (this == obj) { | ||
90 | + return true; | ||
91 | + } | ||
92 | + if (obj == null || getClass() != obj.getClass()) { | ||
93 | + return false; | ||
94 | + } | ||
95 | + final Bmv2FlowRuleWrapper other = (Bmv2FlowRuleWrapper) obj; | ||
96 | + return Objects.equal(this.rule, other.rule) | ||
97 | + && Objects.equal(this.entryId, other.entryId) | ||
98 | + && Objects.equal(this.creationDate, other.creationDate); | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
102 | + public String toString() { | ||
103 | + return creationDate + "-" + rule.hashCode(); | ||
104 | + } | ||
105 | +} |
... | @@ -24,9 +24,9 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -24,9 +24,9 @@ import static com.google.common.base.Preconditions.checkArgument; |
24 | import static com.google.common.base.Preconditions.checkNotNull; | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
25 | 25 | ||
26 | /** | 26 | /** |
27 | - * Representation of a Bmv2 longest prefix match (LPM) parameter. | 27 | + * Representation of a BMv2 longest prefix match (LPM) parameter. |
28 | */ | 28 | */ |
29 | -public class Bmv2LpmMatchParam implements Bmv2MatchParam { | 29 | +public final class Bmv2LpmMatchParam implements Bmv2MatchParam { |
30 | 30 | ||
31 | private final ImmutableByteSequence value; | 31 | private final ImmutableByteSequence value; |
32 | private final int prefixLength; | 32 | private final int prefixLength; | ... | ... |
... | @@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkArgument; |
28 | import static com.google.common.base.Preconditions.checkNotNull; | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | - * Bmv2 match key representation. | 31 | + * A match key of a BMv2 match-action table entry. |
32 | */ | 32 | */ |
33 | public final class Bmv2MatchKey { | 33 | public final class Bmv2MatchKey { |
34 | 34 | ||
... | @@ -39,13 +39,17 @@ public final class Bmv2MatchKey { | ... | @@ -39,13 +39,17 @@ public final class Bmv2MatchKey { |
39 | this.matchParams = matchParams; | 39 | this.matchParams = matchParams; |
40 | } | 40 | } |
41 | 41 | ||
42 | + /** | ||
43 | + * Returns a new match key builder. | ||
44 | + * | ||
45 | + * @return a match key builder | ||
46 | + */ | ||
42 | public static Builder builder() { | 47 | public static Builder builder() { |
43 | return new Builder(); | 48 | return new Builder(); |
44 | } | 49 | } |
45 | 50 | ||
46 | /** | 51 | /** |
47 | - * Returns an immutable view of the ordered list of match parameters of this | 52 | + * Returns the list of match parameters of this match key. |
48 | - * match key. | ||
49 | * | 53 | * |
50 | * @return list match parameters | 54 | * @return list match parameters |
51 | */ | 55 | */ |
... | @@ -79,7 +83,7 @@ public final class Bmv2MatchKey { | ... | @@ -79,7 +83,7 @@ public final class Bmv2MatchKey { |
79 | } | 83 | } |
80 | 84 | ||
81 | /** | 85 | /** |
82 | - * Builder of a Bmv2 match key. | 86 | + * Builder of a BMv2 match key. |
83 | */ | 87 | */ |
84 | public static final class Builder { | 88 | public static final class Builder { |
85 | 89 | ||
... | @@ -89,6 +93,12 @@ public final class Bmv2MatchKey { | ... | @@ -89,6 +93,12 @@ public final class Bmv2MatchKey { |
89 | this.matchParams = Lists.newArrayList(); | 93 | this.matchParams = Lists.newArrayList(); |
90 | } | 94 | } |
91 | 95 | ||
96 | + /** | ||
97 | + * Adds a match parameter to the match key. | ||
98 | + * | ||
99 | + * @param param a match parameter | ||
100 | + * @return this | ||
101 | + */ | ||
92 | public Builder add(Bmv2MatchParam param) { | 102 | public Builder add(Bmv2MatchParam param) { |
93 | this.matchParams.add(checkNotNull(param)); | 103 | this.matchParams.add(checkNotNull(param)); |
94 | return this; | 104 | return this; | ... | ... |
... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
17 | package org.onosproject.bmv2.api.runtime; | 17 | package org.onosproject.bmv2.api.runtime; |
18 | 18 | ||
19 | /** | 19 | /** |
20 | - * Representation of a Bmv2 match parameter. | 20 | + * Representation of a BMv2 match parameter. |
21 | */ | 21 | */ |
22 | public interface Bmv2MatchParam { | 22 | public interface Bmv2MatchParam { |
23 | 23 | ||
... | @@ -29,7 +29,7 @@ public interface Bmv2MatchParam { | ... | @@ -29,7 +29,7 @@ public interface Bmv2MatchParam { |
29 | Type type(); | 29 | Type type(); |
30 | 30 | ||
31 | /** | 31 | /** |
32 | - * Bmv2 match types. | 32 | + * BMv2 match types. |
33 | */ | 33 | */ |
34 | enum Type { | 34 | enum Type { |
35 | /** | 35 | /** | ... | ... |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2ParsedTableEntry.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.runtime; | ||
18 | + | ||
19 | +import com.google.common.base.MoreObjects; | ||
20 | +import com.google.common.base.Objects; | ||
21 | + | ||
22 | +/** | ||
23 | + * Representation of a table entry obtained by parsing a BMv2 table dump. | ||
24 | + */ | ||
25 | +public final class Bmv2ParsedTableEntry { | ||
26 | + private final long entryId; | ||
27 | + private final Bmv2MatchKey matchKey; | ||
28 | + private final Bmv2Action action; | ||
29 | + | ||
30 | + /** | ||
31 | + * Creates a new parsed table entry. | ||
32 | + * | ||
33 | + * @param entryId an entry ID | ||
34 | + * @param matchKey a match key | ||
35 | + * @param action an action | ||
36 | + */ | ||
37 | + public Bmv2ParsedTableEntry(long entryId, Bmv2MatchKey matchKey, Bmv2Action action) { | ||
38 | + this.entryId = entryId; | ||
39 | + this.matchKey = matchKey; | ||
40 | + this.action = action; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Returns the entry ID. | ||
45 | + * | ||
46 | + * @return a long value | ||
47 | + */ | ||
48 | + public long entryId() { | ||
49 | + return entryId; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Returns the match key. | ||
54 | + * | ||
55 | + * @return a match key object | ||
56 | + */ | ||
57 | + public Bmv2MatchKey matchKey() { | ||
58 | + return matchKey; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Returns the action. | ||
63 | + * | ||
64 | + * @return an action object | ||
65 | + */ | ||
66 | + public Bmv2Action action() { | ||
67 | + return action; | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public int hashCode() { | ||
72 | + return Objects.hashCode(entryId, matchKey, action); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public boolean equals(Object obj) { | ||
77 | + if (this == obj) { | ||
78 | + return true; | ||
79 | + } | ||
80 | + if (obj == null || getClass() != obj.getClass()) { | ||
81 | + return false; | ||
82 | + } | ||
83 | + final Bmv2ParsedTableEntry other = (Bmv2ParsedTableEntry) obj; | ||
84 | + return Objects.equal(this.entryId, other.entryId) | ||
85 | + && Objects.equal(this.matchKey, other.matchKey) | ||
86 | + && Objects.equal(this.action, other.action); | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public String toString() { | ||
91 | + return MoreObjects.toStringHelper(this) | ||
92 | + .add("entryId", entryId) | ||
93 | + .add("matchKey", matchKey) | ||
94 | + .add("action", action) | ||
95 | + .toString(); | ||
96 | + } | ||
97 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.runtime; | ||
18 | + | ||
19 | +import com.google.common.base.MoreObjects; | ||
20 | +import com.google.common.base.Objects; | ||
21 | + | ||
22 | +/** | ||
23 | + * Information of a port of a BMv2 device. | ||
24 | + */ | ||
25 | +public final class Bmv2PortInfo { | ||
26 | + | ||
27 | + private final String ifaceName; | ||
28 | + private final int number; | ||
29 | + private final boolean isUp; | ||
30 | + | ||
31 | + /** | ||
32 | + * Creates a new port description. | ||
33 | + * | ||
34 | + * @param ifaceName the common name of the network interface | ||
35 | + * @param number a port number | ||
36 | + * @param isUp interface status | ||
37 | + */ | ||
38 | + public Bmv2PortInfo(String ifaceName, int number, boolean isUp) { | ||
39 | + this.ifaceName = ifaceName; | ||
40 | + this.number = number; | ||
41 | + this.isUp = isUp; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the common name the network interface used by this port. | ||
46 | + * | ||
47 | + * @return a string value | ||
48 | + */ | ||
49 | + public String ifaceName() { | ||
50 | + return ifaceName; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Returns the number of this port. | ||
55 | + * | ||
56 | + * @return an integer value | ||
57 | + */ | ||
58 | + public int number() { | ||
59 | + return number; | ||
60 | + } | ||
61 | + | ||
62 | + /** | ||
63 | + * Returns true if the port is up, false otherwise. | ||
64 | + * | ||
65 | + * @return a boolean value | ||
66 | + */ | ||
67 | + public boolean isUp() { | ||
68 | + return isUp; | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public int hashCode() { | ||
73 | + return Objects.hashCode(ifaceName, number, isUp); | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public boolean equals(Object obj) { | ||
78 | + if (this == obj) { | ||
79 | + return true; | ||
80 | + } | ||
81 | + if (obj == null || getClass() != obj.getClass()) { | ||
82 | + return false; | ||
83 | + } | ||
84 | + final Bmv2PortInfo other = (Bmv2PortInfo) obj; | ||
85 | + return Objects.equal(this.ifaceName, other.ifaceName) | ||
86 | + && Objects.equal(this.number, other.number) | ||
87 | + && Objects.equal(this.isUp, other.isUp); | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public String toString() { | ||
92 | + return MoreObjects.toStringHelper(this) | ||
93 | + .add("ifaceName", ifaceName) | ||
94 | + .add("number", number) | ||
95 | + .add("isUp", isUp) | ||
96 | + .toString(); | ||
97 | + } | ||
98 | +} |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2RuntimeException.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.runtime; | ||
18 | + | ||
19 | +/** | ||
20 | + * General exception of the BMv2 runtime APIs. | ||
21 | + */ | ||
22 | +public final class Bmv2RuntimeException extends Exception { | ||
23 | + | ||
24 | + private final Code code; | ||
25 | + private String codeString; | ||
26 | + | ||
27 | + public Bmv2RuntimeException(String message) { | ||
28 | + super(message); | ||
29 | + this.code = Code.OTHER; | ||
30 | + this.codeString = message; | ||
31 | + } | ||
32 | + | ||
33 | + public Bmv2RuntimeException(Throwable cause) { | ||
34 | + super(cause); | ||
35 | + this.code = Code.OTHER; | ||
36 | + this.codeString = cause.toString(); | ||
37 | + } | ||
38 | + | ||
39 | + public Bmv2RuntimeException(Code code) { | ||
40 | + super(code.name()); | ||
41 | + this.code = code; | ||
42 | + } | ||
43 | + | ||
44 | + public Code getCode() { | ||
45 | + return this.code; | ||
46 | + } | ||
47 | + | ||
48 | + public String explain() { | ||
49 | + return (codeString == null) ? code.name() : code.name() + " " + codeString; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public String toString() { | ||
54 | + return getClass().getSimpleName() + " " + explain(); | ||
55 | + } | ||
56 | + | ||
57 | + public enum Code { | ||
58 | + TABLE_FULL, | ||
59 | + TABLE_INVALID_HANDLE, | ||
60 | + TABLE_EXPIRED_HANDLE, | ||
61 | + TABLE_COUNTERS_DISABLED, | ||
62 | + TABLE_METERS_DISABLED, | ||
63 | + TABLE_AGEING_DISABLED, | ||
64 | + TABLE_INVALID_TABLE_NAME, | ||
65 | + TABLE_INVALID_ACTION_NAME, | ||
66 | + TABLE_WRONG_TABLE_TYPE, | ||
67 | + TABLE_INVALID_MBR_HANDLE, | ||
68 | + TABLE_MBR_STILL_USED, | ||
69 | + TABLE_MBR_ALREADY_IN_GRP, | ||
70 | + TABLE_MBR_NOT_IN_GRP, | ||
71 | + TABLE_INVALID_GRP_HANDLE, | ||
72 | + TABLE_GRP_STILL_USED, | ||
73 | + TABLE_EMPTY_GRP, | ||
74 | + TABLE_DUPLICATE_ENTRY, | ||
75 | + TABLE_BAD_MATCH_KEY, | ||
76 | + TABLE_INVALID_METER_OPERATION, | ||
77 | + TABLE_DEFAULT_ACTION_IS_CONST, | ||
78 | + TABLE_DEFAULT_ENTRY_IS_CONST, | ||
79 | + TABLE_GENERAL_ERROR, | ||
80 | + TABLE_UNKNOWN_ERROR, | ||
81 | + | ||
82 | + DEV_MGR_ERROR_GENERAL, | ||
83 | + DEV_MGR_UNKNOWN, | ||
84 | + | ||
85 | + COUNTER_INVALID_NAME, | ||
86 | + COUNTER_INVALID_INDEX, | ||
87 | + COUNTER_ERROR_GENERAL, | ||
88 | + COUNTER_ERROR_UNKNOWN, | ||
89 | + | ||
90 | + SWAP_CONFIG_DISABLED, | ||
91 | + SWAP_ONGOING, | ||
92 | + SWAP_NO_ONGOING, | ||
93 | + SWAP_ERROR_UKNOWN, | ||
94 | + | ||
95 | + // TODO: add other codes based on autogenerated Thrift APIs | ||
96 | + | ||
97 | + OTHER | ||
98 | + } | ||
99 | +} |
... | @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkArgument; |
22 | import static com.google.common.base.Preconditions.checkNotNull; | 22 | import static com.google.common.base.Preconditions.checkNotNull; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | - * Bmv2 representation of a table entry. | 25 | + * An entry of a match-action table in a BMv2 device. |
26 | */ | 26 | */ |
27 | public final class Bmv2TableEntry { | 27 | public final class Bmv2TableEntry { |
28 | 28 | ||
... | @@ -45,7 +45,7 @@ public final class Bmv2TableEntry { | ... | @@ -45,7 +45,7 @@ public final class Bmv2TableEntry { |
45 | } | 45 | } |
46 | 46 | ||
47 | /** | 47 | /** |
48 | - * Returns a new Bmv2 table entry builder. | 48 | + * Returns a new BMv2 table entry builder. |
49 | * | 49 | * |
50 | * @return a new builder. | 50 | * @return a new builder. |
51 | */ | 51 | */ |
... | @@ -63,7 +63,7 @@ public final class Bmv2TableEntry { | ... | @@ -63,7 +63,7 @@ public final class Bmv2TableEntry { |
63 | } | 63 | } |
64 | 64 | ||
65 | /** | 65 | /** |
66 | - * Returns the match key. | 66 | + * Returns the match key of this table entry. |
67 | * | 67 | * |
68 | * @return match key | 68 | * @return match key |
69 | */ | 69 | */ |
... | @@ -72,7 +72,7 @@ public final class Bmv2TableEntry { | ... | @@ -72,7 +72,7 @@ public final class Bmv2TableEntry { |
72 | } | 72 | } |
73 | 73 | ||
74 | /** | 74 | /** |
75 | - * Returns the action. | 75 | + * Returns the action of this table entry. |
76 | * | 76 | * |
77 | * @return action | 77 | * @return action |
78 | */ | 78 | */ |
... | @@ -81,7 +81,7 @@ public final class Bmv2TableEntry { | ... | @@ -81,7 +81,7 @@ public final class Bmv2TableEntry { |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | - * Returns true is the entry has a valid priority value set. | 84 | + * Returns true is the entry has a valid priority. |
85 | * | 85 | * |
86 | * @return true if priority is set, false elsewhere | 86 | * @return true if priority is set, false elsewhere |
87 | */ | 87 | */ |
... | @@ -90,7 +90,7 @@ public final class Bmv2TableEntry { | ... | @@ -90,7 +90,7 @@ public final class Bmv2TableEntry { |
90 | } | 90 | } |
91 | 91 | ||
92 | /** | 92 | /** |
93 | - * Return the entry priority. | 93 | + * Return the priority of this table entry. |
94 | * | 94 | * |
95 | * @return priority | 95 | * @return priority |
96 | */ | 96 | */ |
... | @@ -99,7 +99,7 @@ public final class Bmv2TableEntry { | ... | @@ -99,7 +99,7 @@ public final class Bmv2TableEntry { |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
102 | - * Returns true is the entry has a valid timeout value set. | 102 | + * Returns true is this table entry has a valid timeout. |
103 | * | 103 | * |
104 | * @return true if timeout is set, false elsewhere | 104 | * @return true if timeout is set, false elsewhere |
105 | */ | 105 | */ |
... | @@ -108,9 +108,9 @@ public final class Bmv2TableEntry { | ... | @@ -108,9 +108,9 @@ public final class Bmv2TableEntry { |
108 | } | 108 | } |
109 | 109 | ||
110 | /** | 110 | /** |
111 | - * Returns the entry timeout in fractional seconds. | 111 | + * Returns the timeout (in fractional seconds) of this table entry. |
112 | * | 112 | * |
113 | - * @return timeout | 113 | + * @return a timeout vale (in fractional seconds) |
114 | */ | 114 | */ |
115 | public final double timeout() { | 115 | public final double timeout() { |
116 | return timeout; | 116 | return timeout; | ... | ... |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/runtime/Bmv2TableEntryReference.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.runtime; | ||
18 | + | ||
19 | +import com.google.common.base.MoreObjects; | ||
20 | +import com.google.common.base.Objects; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | + | ||
23 | +/** | ||
24 | + * A reference to a table entry installed on a BMv2 device. | ||
25 | + */ | ||
26 | +public final class Bmv2TableEntryReference { | ||
27 | + | ||
28 | + | ||
29 | + private final DeviceId deviceId; | ||
30 | + private final String tableName; | ||
31 | + private final Bmv2MatchKey matchKey; | ||
32 | + | ||
33 | + /** | ||
34 | + * Creates a new table entry reference. | ||
35 | + * | ||
36 | + * @param deviceId a device ID | ||
37 | + * @param tableName a table name | ||
38 | + * @param matchKey a match key | ||
39 | + */ | ||
40 | + public Bmv2TableEntryReference(DeviceId deviceId, String tableName, Bmv2MatchKey matchKey) { | ||
41 | + this.deviceId = deviceId; | ||
42 | + this.tableName = tableName; | ||
43 | + this.matchKey = matchKey; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the device ID of this table entry reference. | ||
48 | + * | ||
49 | + * @return a device ID | ||
50 | + */ | ||
51 | + public DeviceId deviceId() { | ||
52 | + return deviceId; | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Returns the name of the table of this table entry reference. | ||
57 | + * | ||
58 | + * @return a table name | ||
59 | + */ | ||
60 | + public String tableName() { | ||
61 | + return tableName; | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Returns the match key of this table entry reference. | ||
66 | + * | ||
67 | + * @return a match key | ||
68 | + */ | ||
69 | + public Bmv2MatchKey matchKey() { | ||
70 | + return matchKey; | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public int hashCode() { | ||
75 | + return Objects.hashCode(deviceId, tableName, matchKey); | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public boolean equals(Object obj) { | ||
80 | + if (this == obj) { | ||
81 | + return true; | ||
82 | + } | ||
83 | + if (obj == null || getClass() != obj.getClass()) { | ||
84 | + return false; | ||
85 | + } | ||
86 | + final Bmv2TableEntryReference other = (Bmv2TableEntryReference) obj; | ||
87 | + return Objects.equal(this.deviceId, other.deviceId) | ||
88 | + && Objects.equal(this.tableName, other.tableName) | ||
89 | + && Objects.equal(this.matchKey, other.matchKey); | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public String toString() { | ||
94 | + return MoreObjects.toStringHelper(this) | ||
95 | + .add("deviceId", deviceId) | ||
96 | + .add("tableName", tableName) | ||
97 | + .add("matchKey", matchKey) | ||
98 | + .toString(); | ||
99 | + } | ||
100 | +} |
... | @@ -24,9 +24,9 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -24,9 +24,9 @@ import static com.google.common.base.Preconditions.checkNotNull; |
24 | import static com.google.common.base.Preconditions.checkState; | 24 | import static com.google.common.base.Preconditions.checkState; |
25 | 25 | ||
26 | /** | 26 | /** |
27 | - * Representation of a Bmv2 ternary match parameter. | 27 | + * Representation of a BMv2 ternary match parameter. |
28 | */ | 28 | */ |
29 | -public class Bmv2TernaryMatchParam implements Bmv2MatchParam { | 29 | +public final class Bmv2TernaryMatchParam implements Bmv2MatchParam { |
30 | 30 | ||
31 | private final ImmutableByteSequence value; | 31 | private final ImmutableByteSequence value; |
32 | private final ImmutableByteSequence mask; | 32 | private final ImmutableByteSequence mask; | ... | ... |
... | @@ -22,9 +22,9 @@ import com.google.common.base.MoreObjects; | ... | @@ -22,9 +22,9 @@ import com.google.common.base.MoreObjects; |
22 | import java.util.Objects; | 22 | import java.util.Objects; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | - * Representation of a Bmv2 valid match parameter. | 25 | + * Representation of a BMv2 valid match parameter. |
26 | */ | 26 | */ |
27 | -public class Bmv2ValidMatchParam implements Bmv2MatchParam { | 27 | +public final class Bmv2ValidMatchParam implements Bmv2MatchParam { |
28 | 28 | ||
29 | private final boolean flag; | 29 | private final boolean flag; |
30 | 30 | ... | ... |
... | @@ -14,70 +14,64 @@ | ... | @@ -14,70 +14,64 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.runtime; | 17 | +package org.onosproject.bmv2.api.service; |
18 | 18 | ||
19 | -import org.onlab.util.ImmutableByteSequence; | 19 | +import org.onosproject.bmv2.api.runtime.Bmv2DeviceAgent; |
20 | +import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException; | ||
21 | +import org.onosproject.net.DeviceId; | ||
20 | 22 | ||
21 | /** | 23 | /** |
22 | - * A server that listens for requests from a BMv2 device. | 24 | + * A controller of BMv2 devices. |
23 | */ | 25 | */ |
24 | -public interface Bmv2ControlPlaneServer { | 26 | +public interface Bmv2Controller { |
27 | + | ||
25 | /** | 28 | /** |
26 | - * Default listening port. | 29 | + * Default port. |
27 | */ | 30 | */ |
28 | int DEFAULT_PORT = 40123; | 31 | int DEFAULT_PORT = 40123; |
29 | 32 | ||
30 | /** | 33 | /** |
31 | - * Register the given hello listener, to be called each time a hello message is received from a BMv2 device. | 34 | + * Return an agent to operate on the given device. |
32 | * | 35 | * |
33 | - * @param listener a hello listener | 36 | + * @param deviceId a device ID |
37 | + * @return a BMv2 agent | ||
38 | + * @throws Bmv2RuntimeException if the agent is not available | ||
34 | */ | 39 | */ |
35 | - void addHelloListener(HelloListener listener); | 40 | + Bmv2DeviceAgent getAgent(DeviceId deviceId) throws Bmv2RuntimeException; |
36 | 41 | ||
37 | /** | 42 | /** |
38 | - * Unregister the given hello listener. | 43 | + * Returns true if the given device is reachable from this controller, false otherwise. |
39 | * | 44 | * |
40 | - * @param listener a hello listener | 45 | + * @param deviceId a device ID |
46 | + * @return a boolean value | ||
41 | */ | 47 | */ |
42 | - void removeHelloListener(HelloListener listener); | 48 | + boolean isReacheable(DeviceId deviceId); |
43 | 49 | ||
44 | /** | 50 | /** |
45 | - * Register the given packet listener, to be called each time a packet-in message is received from a BMv2 device. | 51 | + * Register the given device listener. |
46 | * | 52 | * |
47 | - * @param listener a packet listener | 53 | + * @param listener a device listener |
48 | */ | 54 | */ |
49 | - void addPacketListener(PacketListener listener); | 55 | + void addDeviceListener(Bmv2DeviceListener listener); |
50 | 56 | ||
51 | /** | 57 | /** |
52 | - * Unregister the given packet listener. | 58 | + * Unregister the given device listener. |
53 | * | 59 | * |
54 | - * @param listener a packet listener | 60 | + * @param listener a device listener |
55 | */ | 61 | */ |
56 | - void removePacketListener(PacketListener listener); | 62 | + void removeDeviceListener(Bmv2DeviceListener listener); |
57 | - | ||
58 | - interface HelloListener { | ||
59 | 63 | ||
60 | /** | 64 | /** |
61 | - * Handles a hello message. | 65 | + * Register the given packet listener. |
62 | * | 66 | * |
63 | - * @param device the BMv2 device that originated the message | 67 | + * @param listener a packet listener |
64 | */ | 68 | */ |
65 | - void handleHello(Bmv2Device device); | 69 | + void addPacketListener(Bmv2PacketListener listener); |
66 | - } | ||
67 | - | ||
68 | - interface PacketListener { | ||
69 | 70 | ||
70 | /** | 71 | /** |
71 | - * Handles a packet-in message. | 72 | + * Unregister the given packet listener. |
72 | * | 73 | * |
73 | - * @param device the BMv2 device that originated the message | 74 | + * @param listener a packet listener |
74 | - * @param inputPort the device port where the packet was received | ||
75 | - * @param reason a reason code | ||
76 | - * @param tableId the table id that originated this packet-in | ||
77 | - * @param contextId the context id where the packet-in was originated | ||
78 | - * @param packet the packet body | ||
79 | */ | 75 | */ |
80 | - void handlePacketIn(Bmv2Device device, int inputPort, long reason, int tableId, int contextId, | 76 | + void removePacketListener(Bmv2PacketListener listener); |
81 | - ImmutableByteSequence packet); | ||
82 | - } | ||
83 | } | 77 | } | ... | ... |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/service/Bmv2DeviceContextService.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.service; | ||
18 | + | ||
19 | +import org.onosproject.bmv2.api.context.Bmv2DeviceContext; | ||
20 | +import org.onosproject.bmv2.api.context.Bmv2Interpreter; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | + | ||
23 | +/** | ||
24 | + * A service for managing BMv2 device contexts. | ||
25 | + */ | ||
26 | +public interface Bmv2DeviceContextService { | ||
27 | + | ||
28 | + // TODO: handle the potential configuration states (e.g. RUNNING, SWAP_REQUESTED, etc.) | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the context of a given device. The context returned is the last one for which a configuration swap was | ||
32 | + * triggered, hence there's no guarantees that the device is enforcing the returned context's configuration at the | ||
33 | + * time of the call. | ||
34 | + * | ||
35 | + * @param deviceId a device ID | ||
36 | + * @return a BMv2 device context | ||
37 | + */ | ||
38 | + Bmv2DeviceContext getContext(DeviceId deviceId); | ||
39 | + | ||
40 | + /** | ||
41 | + * Triggers a configuration swap on a given device. | ||
42 | + * | ||
43 | + * @param deviceId a device ID | ||
44 | + * @param context a BMv2 device context | ||
45 | + */ | ||
46 | + void triggerConfigurationSwap(DeviceId deviceId, Bmv2DeviceContext context); | ||
47 | + | ||
48 | + /** | ||
49 | + * Binds the given interpreter with the given class loader so that other ONOS instances in the cluster can properly | ||
50 | + * load the interpreter. | ||
51 | + * | ||
52 | + * @param interpreterClass an interpreter class | ||
53 | + * @param loader a class loader | ||
54 | + */ | ||
55 | + void registerInterpreterClassLoader(Class<? extends Bmv2Interpreter> interpreterClass, ClassLoader loader); | ||
56 | + | ||
57 | + /** | ||
58 | + * Notifies this service that a given device has been updated, meaning a potential context change. | ||
59 | + * It returns true if the device configuration is the same as the last for which a swap was triggered, false | ||
60 | + * otherwise. In the last case, the service will asynchronously trigger a swap to the last | ||
61 | + * configuration stored by this service. If no swap has already been triggered then a default configuration will be | ||
62 | + * applied. | ||
63 | + * | ||
64 | + * @param deviceId a device ID | ||
65 | + * @return a boolean value | ||
66 | + */ | ||
67 | + boolean notifyDeviceChange(DeviceId deviceId); | ||
68 | +} |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/service/Bmv2DeviceListener.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.service; | ||
18 | + | ||
19 | +import org.onosproject.bmv2.api.runtime.Bmv2Device; | ||
20 | + | ||
21 | +/** | ||
22 | + * A listener of BMv2 device events. | ||
23 | + */ | ||
24 | +public interface Bmv2DeviceListener { | ||
25 | + | ||
26 | + /** | ||
27 | + * Handles a hello message. | ||
28 | + * | ||
29 | + * @param device the BMv2 device that originated the message | ||
30 | + * @param instanceId the ID of the BMv2 process instance | ||
31 | + * @param jsonConfigMd5 the MD5 sum of the JSON configuration currently running on the device | ||
32 | + */ | ||
33 | + void handleHello(Bmv2Device device, int instanceId, String jsonConfigMd5); | ||
34 | +} |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/service/Bmv2PacketListener.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.service; | ||
18 | + | ||
19 | +import org.onlab.util.ImmutableByteSequence; | ||
20 | +import org.onosproject.bmv2.api.runtime.Bmv2Device; | ||
21 | + | ||
22 | +/** | ||
23 | + * A listener of BMv2 packet events. | ||
24 | + */ | ||
25 | +public interface Bmv2PacketListener { | ||
26 | + | ||
27 | + /** | ||
28 | + * Handles a packet-in message. | ||
29 | + * | ||
30 | + * @param device the BMv2 device that originated the message | ||
31 | + * @param inputPort the device port where the packet was received | ||
32 | + * @param reason a reason code | ||
33 | + * @param tableId the ID of table that originated this packet-in | ||
34 | + * @param contextId the ID of the BMv2 context where the packet-in was originated | ||
35 | + * @param packet the packet raw data | ||
36 | + */ | ||
37 | + void handlePacketIn(Bmv2Device device, int inputPort, long reason, int tableId, int contextId, | ||
38 | + ImmutableByteSequence packet); | ||
39 | +} |
protocols/bmv2/api/src/main/java/org/onosproject/bmv2/api/service/Bmv2TableEntryService.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.service; | ||
18 | + | ||
19 | + | ||
20 | +import org.onosproject.bmv2.api.context.Bmv2FlowRuleTranslator; | ||
21 | +import org.onosproject.bmv2.api.runtime.Bmv2FlowRuleWrapper; | ||
22 | +import org.onosproject.bmv2.api.runtime.Bmv2ParsedTableEntry; | ||
23 | +import org.onosproject.bmv2.api.runtime.Bmv2TableEntryReference; | ||
24 | +import org.onosproject.net.DeviceId; | ||
25 | + | ||
26 | +import java.util.List; | ||
27 | + | ||
28 | +/** | ||
29 | + * A service for managing BMv2 table entries. | ||
30 | + */ | ||
31 | +public interface Bmv2TableEntryService { | ||
32 | + | ||
33 | + /** | ||
34 | + * Returns a flow rule translator. | ||
35 | + * | ||
36 | + * @return a flow rule translator | ||
37 | + */ | ||
38 | + Bmv2FlowRuleTranslator getFlowRuleTranslator(); | ||
39 | + | ||
40 | + /** | ||
41 | + * Returns a list of table entries installed in the given device and table. The table entries returned are the | ||
42 | + * result of a table dump parse. | ||
43 | + * | ||
44 | + * @param deviceId a device id | ||
45 | + * @param tableName a table name | ||
46 | + * @return a list of parsed table entries | ||
47 | + */ | ||
48 | + List<Bmv2ParsedTableEntry> getTableEntries(DeviceId deviceId, String tableName); | ||
49 | + | ||
50 | + /** | ||
51 | + * Binds the given ONOS flow rule with a BMv2 table entry reference. | ||
52 | + * | ||
53 | + * @param entryRef a table entry reference | ||
54 | + * @param rule a BMv2 flow rule wrapper | ||
55 | + */ | ||
56 | + void bindEntryReference(Bmv2TableEntryReference entryRef, Bmv2FlowRuleWrapper rule); | ||
57 | + | ||
58 | + /** | ||
59 | + * Returns the ONOS flow rule associated with the given BMv2 table entry reference, or null if there's no such a | ||
60 | + * mapping. | ||
61 | + * | ||
62 | + * @param entryRef a table entry reference | ||
63 | + * @return a BMv2 flow rule wrapper | ||
64 | + */ | ||
65 | + Bmv2FlowRuleWrapper lookupEntryReference(Bmv2TableEntryReference entryRef); | ||
66 | + | ||
67 | + /** | ||
68 | + * Removes any flow rule previously bound with a given BMv2 table entry reference. | ||
69 | + * | ||
70 | + * @param entryRef a table entry reference | ||
71 | + */ | ||
72 | + void unbindEntryReference(Bmv2TableEntryReference entryRef); | ||
73 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +/** | ||
18 | + * BMv2 service API. | ||
19 | + */ | ||
20 | +package org.onosproject.bmv2.api.service; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.api.utils; | ||
18 | + | ||
19 | +import org.onlab.util.HexString; | ||
20 | +import org.onlab.util.ImmutableByteSequence; | ||
21 | + | ||
22 | +import java.util.Arrays; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkArgument; | ||
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | + | ||
27 | +/** | ||
28 | + * Collection of util methods to deal with flow rule translation. | ||
29 | + */ | ||
30 | +public final class Bmv2TranslatorUtils { | ||
31 | + | ||
32 | + private Bmv2TranslatorUtils() { | ||
33 | + // Ban constructor. | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * Returns the number of bytes necessary to contain the given bit-width. | ||
38 | + * | ||
39 | + * @param bitWidth an integer value | ||
40 | + * @return an integer value | ||
41 | + */ | ||
42 | + public static int roundToBytes(int bitWidth) { | ||
43 | + return (int) Math.ceil((double) bitWidth / 8); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Trims or expands the given byte sequence so to fit a given bit-width. | ||
48 | + * | ||
49 | + * @param original a byte sequence | ||
50 | + * @param bitWidth an integer value | ||
51 | + * @return a new byte sequence | ||
52 | + * @throws ByteSequenceFitException if the byte sequence cannot be fitted in the given bit-width | ||
53 | + */ | ||
54 | + public static ImmutableByteSequence fitByteSequence(ImmutableByteSequence original, int bitWidth) | ||
55 | + throws ByteSequenceFitException { | ||
56 | + | ||
57 | + checkNotNull(original, "byte sequence cannot be null"); | ||
58 | + checkArgument(bitWidth > 0, "byte width must a non-zero positive integer"); | ||
59 | + | ||
60 | + int newByteWidth = roundToBytes(bitWidth); | ||
61 | + | ||
62 | + if (original.size() == newByteWidth) { | ||
63 | + // nothing to do | ||
64 | + return original; | ||
65 | + } | ||
66 | + | ||
67 | + byte[] originalBytes = original.asArray(); | ||
68 | + | ||
69 | + if (newByteWidth > original.size()) { | ||
70 | + // pad missing bytes with zeros | ||
71 | + return ImmutableByteSequence.copyFrom(Arrays.copyOf(originalBytes, newByteWidth)); | ||
72 | + } | ||
73 | + | ||
74 | + byte[] newBytes = new byte[newByteWidth]; | ||
75 | + // ImmutableByteSequence is always big-endian, hence check the array in reverse order | ||
76 | + int diff = originalBytes.length - newByteWidth; | ||
77 | + for (int i = originalBytes.length - 1; i > 0; i--) { | ||
78 | + byte ob = originalBytes[i]; // original byte | ||
79 | + byte nb; // new byte | ||
80 | + if (i > diff) { | ||
81 | + // no need to truncate, copy as is | ||
82 | + nb = ob; | ||
83 | + } else if (i == diff) { | ||
84 | + // truncate this byte, check if we're loosing something | ||
85 | + byte mask = (byte) ((1 >> ((bitWidth % 8) + 1)) - 1); | ||
86 | + if ((ob & ~mask) != 0) { | ||
87 | + throw new ByteSequenceFitException(originalBytes, bitWidth); | ||
88 | + } else { | ||
89 | + nb = (byte) (ob & mask); | ||
90 | + } | ||
91 | + } else { | ||
92 | + // drop this byte, check if we're loosing something | ||
93 | + if (originalBytes[i] != 0) { | ||
94 | + throw new ByteSequenceFitException(originalBytes, bitWidth); | ||
95 | + } else { | ||
96 | + continue; | ||
97 | + } | ||
98 | + } | ||
99 | + newBytes[i - diff] = nb; | ||
100 | + } | ||
101 | + | ||
102 | + return ImmutableByteSequence.copyFrom(newBytes); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * A byte sequence fit exception. | ||
107 | + */ | ||
108 | + public static class ByteSequenceFitException extends Exception { | ||
109 | + public ByteSequenceFitException(byte[] bytes, int bitWidth) { | ||
110 | + super("cannot fit " + HexString.toHexString(bytes) + " into a " + bitWidth + " bits value"); | ||
111 | + } | ||
112 | + } | ||
113 | +} |
... | @@ -14,45 +14,7 @@ | ... | @@ -14,45 +14,7 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.runtime; | ||
18 | - | ||
19 | -import com.google.common.base.MoreObjects; | ||
20 | -import org.p4.bmv2.thrift.DevMgrPortInfo; | ||
21 | - | ||
22 | -import java.util.Collections; | ||
23 | -import java.util.Map; | ||
24 | - | ||
25 | /** | 17 | /** |
26 | - * Bmv2 representation of a switch port information. | 18 | + * BMv2 utils. |
27 | */ | 19 | */ |
28 | -public final class Bmv2PortInfo { | 20 | +package org.onosproject.bmv2.api.utils; |
29 | - | ||
30 | - private final DevMgrPortInfo portInfo; | ||
31 | - | ||
32 | - public Bmv2PortInfo(DevMgrPortInfo portInfo) { | ||
33 | - this.portInfo = portInfo; | ||
34 | - } | ||
35 | - | ||
36 | - public final String ifaceName() { | ||
37 | - return portInfo.getIface_name(); | ||
38 | - } | ||
39 | - | ||
40 | - public final int portNumber() { | ||
41 | - return portInfo.getPort_num(); | ||
42 | - } | ||
43 | - | ||
44 | - public final boolean isUp() { | ||
45 | - return portInfo.isIs_up(); | ||
46 | - } | ||
47 | - | ||
48 | - public final Map<String, String> getExtraProperties() { | ||
49 | - return Collections.unmodifiableMap(portInfo.getExtra()); | ||
50 | - } | ||
51 | - | ||
52 | - @Override | ||
53 | - public final String toString() { | ||
54 | - return MoreObjects.toStringHelper(this) | ||
55 | - .addValue(portInfo) | ||
56 | - .toString(); | ||
57 | - } | ||
58 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -14,11 +14,12 @@ | ... | @@ -14,11 +14,12 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.api.context; |
18 | 18 | ||
19 | import com.eclipsesource.json.Json; | 19 | import com.eclipsesource.json.Json; |
20 | import com.eclipsesource.json.JsonObject; | 20 | import com.eclipsesource.json.JsonObject; |
21 | import com.google.common.testing.EqualsTester; | 21 | import com.google.common.testing.EqualsTester; |
22 | +import org.hamcrest.collection.IsIterableContainingInOrder; | ||
22 | import org.junit.Before; | 23 | import org.junit.Before; |
23 | import org.junit.Test; | 24 | import org.junit.Test; |
24 | import org.onosproject.bmv2.api.runtime.Bmv2MatchParam; | 25 | import org.onosproject.bmv2.api.runtime.Bmv2MatchParam; |
... | @@ -30,13 +31,12 @@ import static org.hamcrest.CoreMatchers.notNullValue; | ... | @@ -30,13 +31,12 @@ import static org.hamcrest.CoreMatchers.notNullValue; |
30 | import static org.hamcrest.MatcherAssert.assertThat; | 31 | import static org.hamcrest.MatcherAssert.assertThat; |
31 | import static org.hamcrest.Matchers.hasSize; | 32 | import static org.hamcrest.Matchers.hasSize; |
32 | import static org.hamcrest.Matchers.is; | 33 | import static org.hamcrest.Matchers.is; |
33 | -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; | ||
34 | import static org.hamcrest.core.IsEqual.equalTo; | 34 | import static org.hamcrest.core.IsEqual.equalTo; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | - * BMv2 model parser test suite. | 37 | + * BMv2 JSON configuration parser test. |
38 | */ | 38 | */ |
39 | -public class Bmv2ModelTest { | 39 | +public class Bmv2ConfigurationTest { |
40 | 40 | ||
41 | private JsonObject json; | 41 | private JsonObject json; |
42 | private JsonObject json2; | 42 | private JsonObject json2; |
... | @@ -44,28 +44,28 @@ public class Bmv2ModelTest { | ... | @@ -44,28 +44,28 @@ public class Bmv2ModelTest { |
44 | @Before | 44 | @Before |
45 | public void setUp() throws Exception { | 45 | public void setUp() throws Exception { |
46 | json = Json.parse(new BufferedReader(new InputStreamReader( | 46 | json = Json.parse(new BufferedReader(new InputStreamReader( |
47 | - this.getClass().getResourceAsStream("/simple_pipeline.json")))).asObject(); | 47 | + this.getClass().getResourceAsStream("/simple.json")))).asObject(); |
48 | json2 = Json.parse(new BufferedReader(new InputStreamReader( | 48 | json2 = Json.parse(new BufferedReader(new InputStreamReader( |
49 | - this.getClass().getResourceAsStream("/simple_pipeline.json")))).asObject(); | 49 | + this.getClass().getResourceAsStream("/simple.json")))).asObject(); |
50 | } | 50 | } |
51 | 51 | ||
52 | @Test | 52 | @Test |
53 | public void testParse() throws Exception { | 53 | public void testParse() throws Exception { |
54 | - Bmv2Model model = Bmv2Model.parse(json); | 54 | + Bmv2Configuration config = Bmv2DefaultConfiguration.parse(json); |
55 | - Bmv2Model model2 = Bmv2Model.parse(json2); | 55 | + Bmv2Configuration config2 = Bmv2DefaultConfiguration.parse(json2); |
56 | 56 | ||
57 | new EqualsTester() | 57 | new EqualsTester() |
58 | - .addEqualityGroup(model, model2) | 58 | + .addEqualityGroup(config, config2) |
59 | .testEquals(); | 59 | .testEquals(); |
60 | 60 | ||
61 | /* Check header types */ | 61 | /* Check header types */ |
62 | - Bmv2ModelHeaderType stdMetaT = model.headerType("standard_metadata_t"); | 62 | + Bmv2HeaderTypeModel stdMetaT = config.headerType("standard_metadata_t"); |
63 | - Bmv2ModelHeaderType ethernetT = model.headerType("ethernet_t"); | 63 | + Bmv2HeaderTypeModel ethernetT = config.headerType("ethernet_t"); |
64 | - Bmv2ModelHeaderType intrinsicMetaT = model.headerType("intrinsic_metadata_t"); | 64 | + Bmv2HeaderTypeModel intrinsicMetaT = config.headerType("intrinsic_metadata_t"); |
65 | 65 | ||
66 | - Bmv2ModelHeaderType stdMetaT2 = model2.headerType("standard_metadata_t"); | 66 | + Bmv2HeaderTypeModel stdMetaT2 = config2.headerType("standard_metadata_t"); |
67 | - Bmv2ModelHeaderType ethernetT2 = model2.headerType("ethernet_t"); | 67 | + Bmv2HeaderTypeModel ethernetT2 = config2.headerType("ethernet_t"); |
68 | - Bmv2ModelHeaderType intrinsicMetaT2 = model2.headerType("intrinsic_metadata_t"); | 68 | + Bmv2HeaderTypeModel intrinsicMetaT2 = config2.headerType("intrinsic_metadata_t"); |
69 | 69 | ||
70 | new EqualsTester() | 70 | new EqualsTester() |
71 | .addEqualityGroup(stdMetaT, stdMetaT2) | 71 | .addEqualityGroup(stdMetaT, stdMetaT2) |
... | @@ -88,7 +88,7 @@ public class Bmv2ModelTest { | ... | @@ -88,7 +88,7 @@ public class Bmv2ModelTest { |
88 | 88 | ||
89 | // check that fields are in order | 89 | // check that fields are in order |
90 | assertThat("Incorrect order for header type fields", | 90 | assertThat("Incorrect order for header type fields", |
91 | - stdMetaT.fields(), contains( | 91 | + stdMetaT.fields(), IsIterableContainingInOrder.contains( |
92 | stdMetaT.field("ingress_port"), | 92 | stdMetaT.field("ingress_port"), |
93 | stdMetaT.field("packet_length"), | 93 | stdMetaT.field("packet_length"), |
94 | stdMetaT.field("egress_spec"), | 94 | stdMetaT.field("egress_spec"), |
... | @@ -99,13 +99,13 @@ public class Bmv2ModelTest { | ... | @@ -99,13 +99,13 @@ public class Bmv2ModelTest { |
99 | stdMetaT.field("_padding"))); | 99 | stdMetaT.field("_padding"))); |
100 | 100 | ||
101 | /* Check actions */ | 101 | /* Check actions */ |
102 | - Bmv2ModelAction floodAction = model.action("flood"); | 102 | + Bmv2ActionModel floodAction = config.action("flood"); |
103 | - Bmv2ModelAction dropAction = model.action("_drop"); | 103 | + Bmv2ActionModel dropAction = config.action("_drop"); |
104 | - Bmv2ModelAction fwdAction = model.action("fwd"); | 104 | + Bmv2ActionModel fwdAction = config.action("set_egress_port"); |
105 | 105 | ||
106 | - Bmv2ModelAction floodAction2 = model2.action("flood"); | 106 | + Bmv2ActionModel floodAction2 = config2.action("flood"); |
107 | - Bmv2ModelAction dropAction2 = model2.action("_drop"); | 107 | + Bmv2ActionModel dropAction2 = config2.action("_drop"); |
108 | - Bmv2ModelAction fwdAction2 = model2.action("fwd"); | 108 | + Bmv2ActionModel fwdAction2 = config2.action("set_egress_port"); |
109 | 109 | ||
110 | new EqualsTester() | 110 | new EqualsTester() |
111 | .addEqualityGroup(floodAction, floodAction2) | 111 | .addEqualityGroup(floodAction, floodAction2) |
... | @@ -133,8 +133,8 @@ public class Bmv2ModelTest { | ... | @@ -133,8 +133,8 @@ public class Bmv2ModelTest { |
133 | fwdAction.runtimeData("port").bitWidth(), is(equalTo(9))); | 133 | fwdAction.runtimeData("port").bitWidth(), is(equalTo(9))); |
134 | 134 | ||
135 | /* Check tables */ | 135 | /* Check tables */ |
136 | - Bmv2ModelTable table0 = model.table(0); | 136 | + Bmv2TableModel table0 = config.table(0); |
137 | - Bmv2ModelTable table02 = model2.table(0); | 137 | + Bmv2TableModel table02 = config2.table(0); |
138 | 138 | ||
139 | new EqualsTester() | 139 | new EqualsTester() |
140 | .addEqualityGroup(table0, table02) | 140 | .addEqualityGroup(table0, table02) | ... | ... |
... | @@ -83,22 +83,6 @@ | ... | @@ -83,22 +83,6 @@ |
83 | ], | 83 | ], |
84 | "length_exp": null, | 84 | "length_exp": null, |
85 | "max_length": null | 85 | "max_length": null |
86 | - }, | ||
87 | - { | ||
88 | - "name": "cpu_header_t", | ||
89 | - "id": 3, | ||
90 | - "fields": [ | ||
91 | - [ | ||
92 | - "device", | ||
93 | - 8 | ||
94 | - ], | ||
95 | - [ | ||
96 | - "reason", | ||
97 | - 8 | ||
98 | - ] | ||
99 | - ], | ||
100 | - "length_exp": null, | ||
101 | - "max_length": null | ||
102 | } | 86 | } |
103 | ], | 87 | ], |
104 | "headers": [ | 88 | "headers": [ |
... | @@ -119,12 +103,6 @@ | ... | @@ -119,12 +103,6 @@ |
119 | "id": 2, | 103 | "id": 2, |
120 | "header_type": "intrinsic_metadata_t", | 104 | "header_type": "intrinsic_metadata_t", |
121 | "metadata": true | 105 | "metadata": true |
122 | - }, | ||
123 | - { | ||
124 | - "name": "cpu_header", | ||
125 | - "id": 3, | ||
126 | - "header_type": "cpu_header_t", | ||
127 | - "metadata": false | ||
128 | } | 106 | } |
129 | ], | 107 | ], |
130 | "header_stacks": [], | 108 | "header_stacks": [], |
... | @@ -138,42 +116,6 @@ | ... | @@ -138,42 +116,6 @@ |
138 | "name": "start", | 116 | "name": "start", |
139 | "id": 0, | 117 | "id": 0, |
140 | "parser_ops": [], | 118 | "parser_ops": [], |
141 | - "transition_key": [ | ||
142 | - { | ||
143 | - "type": "lookahead", | ||
144 | - "value": [ | ||
145 | - 0, | ||
146 | - 64 | ||
147 | - ] | ||
148 | - } | ||
149 | - ], | ||
150 | - "transitions": [ | ||
151 | - { | ||
152 | - "value": "0x0000000000000000", | ||
153 | - "mask": null, | ||
154 | - "next_state": "parse_cpu_header" | ||
155 | - }, | ||
156 | - { | ||
157 | - "value": "default", | ||
158 | - "mask": null, | ||
159 | - "next_state": "parse_ethernet" | ||
160 | - } | ||
161 | - ] | ||
162 | - }, | ||
163 | - { | ||
164 | - "name": "parse_cpu_header", | ||
165 | - "id": 1, | ||
166 | - "parser_ops": [ | ||
167 | - { | ||
168 | - "op": "extract", | ||
169 | - "parameters": [ | ||
170 | - { | ||
171 | - "type": "regular", | ||
172 | - "value": "cpu_header" | ||
173 | - } | ||
174 | - ] | ||
175 | - } | ||
176 | - ], | ||
177 | "transition_key": [], | 119 | "transition_key": [], |
178 | "transitions": [ | 120 | "transitions": [ |
179 | { | 121 | { |
... | @@ -185,7 +127,7 @@ | ... | @@ -185,7 +127,7 @@ |
185 | }, | 127 | }, |
186 | { | 128 | { |
187 | "name": "parse_ethernet", | 129 | "name": "parse_ethernet", |
188 | - "id": 2, | 130 | + "id": 1, |
189 | "parser_ops": [ | 131 | "parser_ops": [ |
190 | { | 132 | { |
191 | "op": "extract", | 133 | "op": "extract", |
... | @@ -214,7 +156,6 @@ | ... | @@ -214,7 +156,6 @@ |
214 | "name": "deparser", | 156 | "name": "deparser", |
215 | "id": 0, | 157 | "id": 0, |
216 | "order": [ | 158 | "order": [ |
217 | - "cpu_header", | ||
218 | "ethernet" | 159 | "ethernet" |
219 | ] | 160 | ] |
220 | } | 161 | } |
... | @@ -222,9 +163,14 @@ | ... | @@ -222,9 +163,14 @@ |
222 | "meter_arrays": [], | 163 | "meter_arrays": [], |
223 | "actions": [ | 164 | "actions": [ |
224 | { | 165 | { |
225 | - "name": "flood", | 166 | + "name": "set_egress_port", |
226 | "id": 0, | 167 | "id": 0, |
227 | - "runtime_data": [], | 168 | + "runtime_data": [ |
169 | + { | ||
170 | + "name": "port", | ||
171 | + "bitwidth": 9 | ||
172 | + } | ||
173 | + ], | ||
228 | "primitives": [ | 174 | "primitives": [ |
229 | { | 175 | { |
230 | "op": "modify_field", | 176 | "op": "modify_field", |
... | @@ -232,16 +178,13 @@ | ... | @@ -232,16 +178,13 @@ |
232 | { | 178 | { |
233 | "type": "field", | 179 | "type": "field", |
234 | "value": [ | 180 | "value": [ |
235 | - "intrinsic_metadata", | 181 | + "standard_metadata", |
236 | - "mcast_grp" | 182 | + "egress_spec" |
237 | ] | 183 | ] |
238 | }, | 184 | }, |
239 | { | 185 | { |
240 | - "type": "field", | 186 | + "type": "runtime_data", |
241 | - "value": [ | 187 | + "value": 0 |
242 | - "standard_metadata", | ||
243 | - "ingress_port" | ||
244 | - ] | ||
245 | } | 188 | } |
246 | ] | 189 | ] |
247 | } | 190 | } |
... | @@ -271,14 +214,9 @@ | ... | @@ -271,14 +214,9 @@ |
271 | ] | 214 | ] |
272 | }, | 215 | }, |
273 | { | 216 | { |
274 | - "name": "fwd", | 217 | + "name": "flood", |
275 | "id": 2, | 218 | "id": 2, |
276 | - "runtime_data": [ | 219 | + "runtime_data": [], |
277 | - { | ||
278 | - "name": "port", | ||
279 | - "bitwidth": 9 | ||
280 | - } | ||
281 | - ], | ||
282 | "primitives": [ | 220 | "primitives": [ |
283 | { | 221 | { |
284 | "op": "modify_field", | 222 | "op": "modify_field", |
... | @@ -286,13 +224,16 @@ | ... | @@ -286,13 +224,16 @@ |
286 | { | 224 | { |
287 | "type": "field", | 225 | "type": "field", |
288 | "value": [ | 226 | "value": [ |
289 | - "standard_metadata", | 227 | + "intrinsic_metadata", |
290 | - "egress_spec" | 228 | + "mcast_grp" |
291 | ] | 229 | ] |
292 | }, | 230 | }, |
293 | { | 231 | { |
294 | - "type": "runtime_data", | 232 | + "type": "field", |
295 | - "value": 0 | 233 | + "value": [ |
234 | + "standard_metadata", | ||
235 | + "ingress_port" | ||
236 | + ] | ||
296 | } | 237 | } |
297 | ] | 238 | ] |
298 | } | 239 | } |
... | @@ -301,59 +242,9 @@ | ... | @@ -301,59 +242,9 @@ |
301 | { | 242 | { |
302 | "name": "send_to_cpu", | 243 | "name": "send_to_cpu", |
303 | "id": 3, | 244 | "id": 3, |
304 | - "runtime_data": [ | 245 | + "runtime_data": [], |
305 | - { | ||
306 | - "name": "device", | ||
307 | - "bitwidth": 8 | ||
308 | - }, | ||
309 | - { | ||
310 | - "name": "reason", | ||
311 | - "bitwidth": 8 | ||
312 | - } | ||
313 | - ], | ||
314 | "primitives": [ | 246 | "primitives": [ |
315 | { | 247 | { |
316 | - "op": "add_header", | ||
317 | - "parameters": [ | ||
318 | - { | ||
319 | - "type": "header", | ||
320 | - "value": "cpu_header" | ||
321 | - } | ||
322 | - ] | ||
323 | - }, | ||
324 | - { | ||
325 | - "op": "modify_field", | ||
326 | - "parameters": [ | ||
327 | - { | ||
328 | - "type": "field", | ||
329 | - "value": [ | ||
330 | - "cpu_header", | ||
331 | - "device" | ||
332 | - ] | ||
333 | - }, | ||
334 | - { | ||
335 | - "type": "runtime_data", | ||
336 | - "value": 0 | ||
337 | - } | ||
338 | - ] | ||
339 | - }, | ||
340 | - { | ||
341 | - "op": "modify_field", | ||
342 | - "parameters": [ | ||
343 | - { | ||
344 | - "type": "field", | ||
345 | - "value": [ | ||
346 | - "cpu_header", | ||
347 | - "reason" | ||
348 | - ] | ||
349 | - }, | ||
350 | - { | ||
351 | - "type": "runtime_data", | ||
352 | - "value": 1 | ||
353 | - } | ||
354 | - ] | ||
355 | - }, | ||
356 | - { | ||
357 | "op": "modify_field", | 248 | "op": "modify_field", |
358 | "parameters": [ | 249 | "parameters": [ |
359 | { | 250 | { |
... | @@ -365,7 +256,7 @@ | ... | @@ -365,7 +256,7 @@ |
365 | }, | 256 | }, |
366 | { | 257 | { |
367 | "type": "hexstr", | 258 | "type": "hexstr", |
368 | - "value": "0xfa" | 259 | + "value": "0xff" |
369 | } | 260 | } |
370 | ] | 261 | ] |
371 | } | 262 | } |
... | @@ -422,18 +313,19 @@ | ... | @@ -422,18 +313,19 @@ |
422 | } | 313 | } |
423 | ], | 314 | ], |
424 | "actions": [ | 315 | "actions": [ |
425 | - "fwd", | 316 | + "set_egress_port", |
426 | "flood", | 317 | "flood", |
427 | "send_to_cpu", | 318 | "send_to_cpu", |
428 | "_drop" | 319 | "_drop" |
429 | ], | 320 | ], |
430 | "next_tables": { | 321 | "next_tables": { |
431 | - "fwd": null, | 322 | + "set_egress_port": null, |
432 | "flood": null, | 323 | "flood": null, |
433 | "send_to_cpu": null, | 324 | "send_to_cpu": null, |
434 | "_drop": null | 325 | "_drop": null |
435 | }, | 326 | }, |
436 | - "default_action": null | 327 | + "default_action": null, |
328 | + "base_default_next": null | ||
437 | } | 329 | } |
438 | ], | 330 | ], |
439 | "conditionals": [] | 331 | "conditionals": [] | ... | ... |
protocols/bmv2/ctl/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | + | ||
18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
19 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
20 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
21 | + <parent> | ||
22 | + <artifactId>onos-bmv2-protocol</artifactId> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <version>1.6.0-SNAPSHOT</version> | ||
25 | + </parent> | ||
26 | + <modelVersion>4.0.0</modelVersion> | ||
27 | + | ||
28 | + <artifactId>onos-bmv2-protocol-ctl</artifactId> | ||
29 | + | ||
30 | + <packaging>bundle</packaging> | ||
31 | + | ||
32 | + <dependencies> | ||
33 | + <dependency> | ||
34 | + <groupId>org.apache.thrift</groupId> | ||
35 | + <artifactId>libthrift</artifactId> | ||
36 | + <version>0.9.3</version> | ||
37 | + </dependency> | ||
38 | + <dependency> | ||
39 | + <groupId>org.onosproject</groupId> | ||
40 | + <artifactId>onos-bmv2-protocol-api</artifactId> | ||
41 | + <version>${project.version}</version> | ||
42 | + </dependency> | ||
43 | + <dependency> | ||
44 | + <groupId>org.onosproject</groupId> | ||
45 | + <artifactId>onos-bmv2-protocol-thrift-api</artifactId> | ||
46 | + <version>${project.version}</version> | ||
47 | + </dependency> | ||
48 | + <dependency> | ||
49 | + <groupId>org.apache.felix</groupId> | ||
50 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
51 | + </dependency> | ||
52 | + <dependency> | ||
53 | + <groupId>org.onosproject</groupId> | ||
54 | + <artifactId>onos-core-serializers</artifactId> | ||
55 | + <version>${project.version}</version> | ||
56 | + </dependency> | ||
57 | + </dependencies> | ||
58 | + | ||
59 | + <build> | ||
60 | + <plugins> | ||
61 | + <plugin> | ||
62 | + <groupId>org.apache.felix</groupId> | ||
63 | + <artifactId>maven-scr-plugin</artifactId> | ||
64 | + </plugin> | ||
65 | + <plugin> | ||
66 | + <groupId>org.onosproject</groupId> | ||
67 | + <artifactId>onos-maven-plugin</artifactId> | ||
68 | + </plugin> | ||
69 | + </plugins> | ||
70 | + </build> | ||
71 | + | ||
72 | + | ||
73 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
protocols/bmv2/ctl/src/main/java/org/onosproject/bmv2/ctl/Bmv2DefaultInterpreterImpl.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.ctl; | ||
18 | + | ||
19 | +import com.google.common.collect.ImmutableBiMap; | ||
20 | +import org.onlab.util.ImmutableByteSequence; | ||
21 | +import org.onosproject.bmv2.api.context.Bmv2Configuration; | ||
22 | +import org.onosproject.bmv2.api.context.Bmv2Interpreter; | ||
23 | +import org.onosproject.bmv2.api.context.Bmv2InterpreterException; | ||
24 | +import org.onosproject.bmv2.api.runtime.Bmv2Action; | ||
25 | +import org.onosproject.bmv2.api.utils.Bmv2TranslatorUtils; | ||
26 | +import org.onosproject.net.flow.TrafficTreatment; | ||
27 | +import org.onosproject.net.flow.criteria.Criterion; | ||
28 | +import org.onosproject.net.flow.instructions.Instruction; | ||
29 | + | ||
30 | +import static org.onosproject.net.PortNumber.CONTROLLER; | ||
31 | +import static org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | ||
32 | + | ||
33 | +/** | ||
34 | + * Implementation of a BMv2 interpreter for the BMv2 default.json configuration. | ||
35 | + */ | ||
36 | +public final class Bmv2DefaultInterpreterImpl implements Bmv2Interpreter { | ||
37 | + | ||
38 | + public static final String TABLE0 = "table0"; | ||
39 | + public static final String SEND_TO_CPU = "send_to_cpu"; | ||
40 | + public static final String DROP = "_drop"; | ||
41 | + public static final String SET_EGRESS_PORT = "set_egress_port"; | ||
42 | + | ||
43 | + // Lazily populate field map. | ||
44 | + private static final ImmutableBiMap<Criterion.Type, String> CRITERION_MAP = ImmutableBiMap.of( | ||
45 | + Criterion.Type.IN_PORT, "standard_metadata.ingress_port", | ||
46 | + Criterion.Type.ETH_DST, "ethernet.dstAddr", | ||
47 | + Criterion.Type.ETH_SRC, "ethernet.srcAddr", | ||
48 | + Criterion.Type.ETH_TYPE, "ethernet.etherType"); | ||
49 | + | ||
50 | + private static final ImmutableBiMap<Integer, String> TABLE_MAP = ImmutableBiMap.of( | ||
51 | + 0, TABLE0); | ||
52 | + | ||
53 | + @Override | ||
54 | + public ImmutableBiMap<Criterion.Type, String> criterionTypeMap() { | ||
55 | + return CRITERION_MAP; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public ImmutableBiMap<Integer, String> tableIdMap() { | ||
60 | + return TABLE_MAP; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public Bmv2Action mapTreatment(TrafficTreatment treatment, Bmv2Configuration configuration) | ||
65 | + throws Bmv2InterpreterException { | ||
66 | + | ||
67 | + | ||
68 | + if (treatment.allInstructions().size() == 0) { | ||
69 | + // No instructions means drop for us. | ||
70 | + return Bmv2Action.builder().withName(DROP).build(); | ||
71 | + } else if (treatment.allInstructions().size() > 1) { | ||
72 | + // Otherwise, we understand treatments with only 1 instruction. | ||
73 | + throw new Bmv2InterpreterException("Treatment has multiple instructions"); | ||
74 | + } | ||
75 | + | ||
76 | + Instruction instruction = treatment.allInstructions().get(0); | ||
77 | + | ||
78 | + switch (instruction.type()) { | ||
79 | + case OUTPUT: | ||
80 | + OutputInstruction outInstruction = (OutputInstruction) instruction; | ||
81 | + if (outInstruction.port() == CONTROLLER) { | ||
82 | + return Bmv2Action.builder().withName(SEND_TO_CPU).build(); | ||
83 | + } else { | ||
84 | + return buildEgressAction(outInstruction, configuration); | ||
85 | + } | ||
86 | + case NOACTION: | ||
87 | + return Bmv2Action.builder().withName(DROP).build(); | ||
88 | + default: | ||
89 | + throw new Bmv2InterpreterException("Instruction type not supported: " + instruction.type().name()); | ||
90 | + } | ||
91 | + } | ||
92 | + | ||
93 | + | ||
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 { | ||
104 | + | ||
105 | + Bmv2Action.Builder actionBuilder = Bmv2Action.builder(); | ||
106 | + | ||
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 { | ||
117 | + ImmutableByteSequence outPort = Bmv2TranslatorUtils.fitByteSequence( | ||
118 | + ImmutableByteSequence.copyFrom(portNumber), bitWidth); | ||
119 | + return Bmv2Action.builder().withName(SET_EGRESS_PORT).addParameter(outPort).build(); | ||
120 | + } catch (Bmv2TranslatorUtils.ByteSequenceFitException e) { | ||
121 | + throw new Bmv2InterpreterException(e.getMessage()); | ||
122 | + } | ||
123 | + } | ||
124 | +} |
protocols/bmv2/ctl/src/main/java/org/onosproject/bmv2/ctl/Bmv2DeviceContextServiceImpl.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.ctl; | ||
18 | + | ||
19 | +import com.eclipsesource.json.Json; | ||
20 | +import com.eclipsesource.json.JsonObject; | ||
21 | +import com.esotericsoftware.kryo.Kryo; | ||
22 | +import com.esotericsoftware.kryo.io.Input; | ||
23 | +import com.esotericsoftware.kryo.io.Output; | ||
24 | +import com.google.common.collect.Maps; | ||
25 | +import org.apache.felix.scr.annotations.Activate; | ||
26 | +import org.apache.felix.scr.annotations.Component; | ||
27 | +import org.apache.felix.scr.annotations.Deactivate; | ||
28 | +import org.apache.felix.scr.annotations.Reference; | ||
29 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
30 | +import org.apache.felix.scr.annotations.Service; | ||
31 | +import org.onlab.util.KryoNamespace; | ||
32 | +import org.onlab.util.SharedExecutors; | ||
33 | +import org.onosproject.bmv2.api.context.Bmv2Configuration; | ||
34 | +import org.onosproject.bmv2.api.context.Bmv2DefaultConfiguration; | ||
35 | +import org.onosproject.bmv2.api.context.Bmv2DeviceContext; | ||
36 | +import org.onosproject.bmv2.api.context.Bmv2Interpreter; | ||
37 | +import org.onosproject.bmv2.api.runtime.Bmv2DeviceAgent; | ||
38 | +import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException; | ||
39 | +import org.onosproject.bmv2.api.service.Bmv2Controller; | ||
40 | +import org.onosproject.bmv2.api.service.Bmv2DeviceContextService; | ||
41 | +import org.onosproject.net.DeviceId; | ||
42 | +import org.onosproject.store.serializers.KryoNamespaces; | ||
43 | +import org.onosproject.store.service.ConsistentMap; | ||
44 | +import org.onosproject.store.service.Serializer; | ||
45 | +import org.onosproject.store.service.StorageService; | ||
46 | +import org.slf4j.Logger; | ||
47 | +import org.slf4j.LoggerFactory; | ||
48 | + | ||
49 | +import java.io.BufferedReader; | ||
50 | +import java.io.IOException; | ||
51 | +import java.io.InputStreamReader; | ||
52 | +import java.util.Map; | ||
53 | +import java.util.concurrent.ExecutorService; | ||
54 | + | ||
55 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
56 | + | ||
57 | +@Component(immediate = true) | ||
58 | +@Service | ||
59 | +public class Bmv2DeviceContextServiceImpl implements Bmv2DeviceContextService { | ||
60 | + | ||
61 | + private static final String JSON_DEFAULT_CONFIG_PATH = "/default.json"; | ||
62 | + | ||
63 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
64 | + private StorageService storageService; | ||
65 | + | ||
66 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
67 | + private Bmv2Controller controller; | ||
68 | + | ||
69 | + private final ExecutorService executorService = SharedExecutors.getPoolThreadExecutor(); | ||
70 | + | ||
71 | + private ConsistentMap<DeviceId, Bmv2DeviceContext> contexts; | ||
72 | + private Map<DeviceId, Bmv2DeviceContext> contextsMap; | ||
73 | + | ||
74 | + private Map<String, ClassLoader> interpreterClassLoaders; | ||
75 | + | ||
76 | + private Bmv2DeviceContext defaultContext; | ||
77 | + | ||
78 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
79 | + | ||
80 | + @Activate | ||
81 | + public void activate() { | ||
82 | + KryoNamespace kryo = new KryoNamespace.Builder() | ||
83 | + .register(KryoNamespaces.API) | ||
84 | + .register(new BmvDeviceContextSerializer(), Bmv2DeviceContext.class) | ||
85 | + .build(); | ||
86 | + | ||
87 | + this.contexts = storageService.<DeviceId, Bmv2DeviceContext>consistentMapBuilder() | ||
88 | + .withSerializer(Serializer.using(kryo)) | ||
89 | + .withName("onos-bmv2-contexts") | ||
90 | + .build(); | ||
91 | + contextsMap = contexts.asJavaMap(); | ||
92 | + | ||
93 | + interpreterClassLoaders = Maps.newConcurrentMap(); | ||
94 | + | ||
95 | + Bmv2Configuration defaultConfiguration = loadDefaultConfiguration(); | ||
96 | + Bmv2Interpreter defaultInterpreter = new Bmv2DefaultInterpreterImpl(); | ||
97 | + defaultContext = new Bmv2DeviceContext(defaultConfiguration, defaultInterpreter); | ||
98 | + | ||
99 | + interpreterClassLoaders.put(defaultInterpreter.getClass().getName(), this.getClass().getClassLoader()); | ||
100 | + | ||
101 | + log.info("Started"); | ||
102 | + } | ||
103 | + | ||
104 | + @Deactivate | ||
105 | + public void deactivate() { | ||
106 | + log.info("Stopped"); | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public Bmv2DeviceContext getContext(DeviceId deviceId) { | ||
111 | + checkNotNull(deviceId, "device id cannot be null"); | ||
112 | + return contextsMap.get(deviceId); | ||
113 | + } | ||
114 | + | ||
115 | + @Override | ||
116 | + public void triggerConfigurationSwap(DeviceId deviceId, Bmv2DeviceContext context) { | ||
117 | + checkNotNull(deviceId, "device id cannot be null"); | ||
118 | + checkNotNull(context, "context cannot be null"); | ||
119 | + if (!interpreterClassLoaders.containsKey(context.interpreter().getClass().getName())) { | ||
120 | + log.error("Unable to trigger configuration swap, missing class loader for context interpreter. " + | ||
121 | + "Please register it with registerInterpreterClassLoader()"); | ||
122 | + } else { | ||
123 | + executorService.execute(() -> executeConfigurationSwap(deviceId, context)); | ||
124 | + } | ||
125 | + } | ||
126 | + | ||
127 | + @Override | ||
128 | + public void registerInterpreterClassLoader(Class<? extends Bmv2Interpreter> interpreterClass, ClassLoader loader) { | ||
129 | + interpreterClassLoaders.put(interpreterClass.getName(), loader); | ||
130 | + } | ||
131 | + | ||
132 | + private void executeConfigurationSwap(DeviceId deviceId, Bmv2DeviceContext context) { | ||
133 | + contexts.compute(deviceId, (key, existingValue) -> { | ||
134 | + if (context.equals(existingValue)) { | ||
135 | + log.info("Dropping swap request as one has already been triggered for the given context."); | ||
136 | + return existingValue; | ||
137 | + } | ||
138 | + try { | ||
139 | + Bmv2DeviceAgent agent = controller.getAgent(deviceId); | ||
140 | + String jsonString = context.configuration().json().toString(); | ||
141 | + agent.loadNewJsonConfig(jsonString); | ||
142 | + agent.swapJsonConfig(); | ||
143 | + return context; | ||
144 | + } catch (Bmv2RuntimeException e) { | ||
145 | + log.error("Unable to swap configuration on {}: {}", deviceId, e.explain()); | ||
146 | + return existingValue; | ||
147 | + } | ||
148 | + }); | ||
149 | + } | ||
150 | + | ||
151 | + @Override | ||
152 | + public boolean notifyDeviceChange(DeviceId deviceId) { | ||
153 | + checkNotNull(deviceId, "device id cannot be null"); | ||
154 | + | ||
155 | + Bmv2DeviceContext storedContext = getContext(deviceId); | ||
156 | + | ||
157 | + if (storedContext == null) { | ||
158 | + log.info("No context previously stored for {}, swapping to DEFAULT_CONTEXT.", deviceId); | ||
159 | + triggerConfigurationSwap(deviceId, defaultContext); | ||
160 | + // Device can be accepted. | ||
161 | + return false; | ||
162 | + } else { | ||
163 | + Bmv2Configuration deviceConfiguration = loadDeviceConfiguration(deviceId); | ||
164 | + if (deviceConfiguration == null) { | ||
165 | + log.warn("Unable to load configuration from device {}", deviceId); | ||
166 | + return false; | ||
167 | + } | ||
168 | + if (storedContext.configuration().equals(deviceConfiguration)) { | ||
169 | + return true; | ||
170 | + } else { | ||
171 | + log.info("Device context is different from the stored one, triggering configuration swap for {}...", | ||
172 | + deviceId); | ||
173 | + triggerConfigurationSwap(deviceId, storedContext); | ||
174 | + return false; | ||
175 | + } | ||
176 | + } | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Load and parse a BMv2 JSON configuration from the given device. | ||
181 | + * | ||
182 | + * @param deviceId a device id | ||
183 | + * @return a BMv2 configuration | ||
184 | + */ | ||
185 | + private Bmv2Configuration loadDeviceConfiguration(DeviceId deviceId) { | ||
186 | + try { | ||
187 | + String jsonString = controller.getAgent(deviceId).dumpJsonConfig(); | ||
188 | + return Bmv2DefaultConfiguration.parse(Json.parse(jsonString).asObject()); | ||
189 | + } catch (Bmv2RuntimeException e) { | ||
190 | + log.warn("Unable to load JSON configuration from {}: {}", deviceId, e.explain()); | ||
191 | + return null; | ||
192 | + } | ||
193 | + } | ||
194 | + | ||
195 | + /** | ||
196 | + * Loads default configuration from file. | ||
197 | + * | ||
198 | + * @return a BMv2 configuration | ||
199 | + */ | ||
200 | + protected static Bmv2DefaultConfiguration loadDefaultConfiguration() { | ||
201 | + try { | ||
202 | + JsonObject json = Json.parse(new BufferedReader(new InputStreamReader( | ||
203 | + Bmv2DeviceContextServiceImpl.class.getResourceAsStream(JSON_DEFAULT_CONFIG_PATH)))).asObject(); | ||
204 | + return Bmv2DefaultConfiguration.parse(json); | ||
205 | + } catch (IOException e) { | ||
206 | + throw new RuntimeException("Unable to load default configuration", e); | ||
207 | + } | ||
208 | + } | ||
209 | + | ||
210 | + /** | ||
211 | + * Internal BMv2 context serializer. | ||
212 | + */ | ||
213 | + private class BmvDeviceContextSerializer extends com.esotericsoftware.kryo.Serializer<Bmv2DeviceContext> { | ||
214 | + | ||
215 | + @Override | ||
216 | + public void write(Kryo kryo, Output output, Bmv2DeviceContext context) { | ||
217 | + kryo.writeObject(output, context.configuration().json().toString()); | ||
218 | + kryo.writeObject(output, context.interpreter().getClass().getName()); | ||
219 | + } | ||
220 | + | ||
221 | + @Override | ||
222 | + public Bmv2DeviceContext read(Kryo kryo, Input input, Class<Bmv2DeviceContext> type) { | ||
223 | + String jsonStr = kryo.readObject(input, String.class); | ||
224 | + String interpreterClassName = kryo.readObject(input, String.class); | ||
225 | + Bmv2Configuration configuration = Bmv2DefaultConfiguration.parse(Json.parse(jsonStr).asObject()); | ||
226 | + ClassLoader loader = interpreterClassLoaders.get(interpreterClassName); | ||
227 | + if (loader == null) { | ||
228 | + throw new IllegalStateException("No class loader registered for interpreter: " + interpreterClassName); | ||
229 | + } | ||
230 | + try { | ||
231 | + Bmv2Interpreter interpreter = (Bmv2Interpreter) loader.loadClass(interpreterClassName).newInstance(); | ||
232 | + return new Bmv2DeviceContext(configuration, interpreter); | ||
233 | + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { | ||
234 | + throw new RuntimeException("Unable to load interpreter class", e); | ||
235 | + } | ||
236 | + } | ||
237 | + } | ||
238 | +} |
This diff is collapsed. Click to expand it.
protocols/bmv2/ctl/src/main/java/org/onosproject/bmv2/ctl/Bmv2FlowRuleTranslatorImpl.java
0 → 100644
This diff is collapsed. Click to expand it.
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.ctl; | ||
18 | + | ||
19 | + | ||
20 | +import org.apache.thrift.TException; | ||
21 | +import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException; | ||
22 | +import org.onosproject.bmv2.thriftapi.InvalidCounterOperation; | ||
23 | +import org.onosproject.bmv2.thriftapi.InvalidDevMgrOperation; | ||
24 | +import org.onosproject.bmv2.thriftapi.InvalidLearnOperation; | ||
25 | +import org.onosproject.bmv2.thriftapi.InvalidMcOperation; | ||
26 | +import org.onosproject.bmv2.thriftapi.InvalidMeterOperation; | ||
27 | +import org.onosproject.bmv2.thriftapi.InvalidRegisterOperation; | ||
28 | +import org.onosproject.bmv2.thriftapi.InvalidSwapOperation; | ||
29 | +import org.onosproject.bmv2.thriftapi.InvalidTableOperation; | ||
30 | + | ||
31 | +import static org.onosproject.bmv2.api.runtime.Bmv2RuntimeException.Code; | ||
32 | + | ||
33 | +/** | ||
34 | + * Utility class to translate a Thrift exception into a Bmv2RuntimeException. | ||
35 | + */ | ||
36 | +final class Bmv2TExceptionParser { | ||
37 | + | ||
38 | + private Bmv2TExceptionParser() { | ||
39 | + // ban constructor. | ||
40 | + } | ||
41 | + | ||
42 | + static Bmv2RuntimeException parseTException(TException cause) { | ||
43 | + try { | ||
44 | + return new Bmv2RuntimeException(getCode(cause)); | ||
45 | + } catch (ParserException e) { | ||
46 | + return new Bmv2RuntimeException(e.codeString); | ||
47 | + } | ||
48 | + } | ||
49 | + | ||
50 | + private static Code getCode(TException e) throws ParserException { | ||
51 | + if (e instanceof InvalidTableOperation) { | ||
52 | + InvalidTableOperation t = (InvalidTableOperation) e; | ||
53 | + switch (t.getCode()) { | ||
54 | + case TABLE_FULL: | ||
55 | + return Code.TABLE_FULL; | ||
56 | + case INVALID_HANDLE: | ||
57 | + return Code.TABLE_INVALID_HANDLE; | ||
58 | + case EXPIRED_HANDLE: | ||
59 | + return Code.TABLE_EXPIRED_HANDLE; | ||
60 | + case COUNTERS_DISABLED: | ||
61 | + return Code.TABLE_COUNTERS_DISABLED; | ||
62 | + case METERS_DISABLED: | ||
63 | + return Code.TABLE_METERS_DISABLED; | ||
64 | + case AGEING_DISABLED: | ||
65 | + return Code.TABLE_AGEING_DISABLED; | ||
66 | + case INVALID_TABLE_NAME: | ||
67 | + return Code.TABLE_INVALID_TABLE_NAME; | ||
68 | + case INVALID_ACTION_NAME: | ||
69 | + return Code.TABLE_INVALID_ACTION_NAME; | ||
70 | + case WRONG_TABLE_TYPE: | ||
71 | + return Code.TABLE_WRONG_TABLE_TYPE; | ||
72 | + case INVALID_MBR_HANDLE: | ||
73 | + return Code.TABLE_INVALID_MBR_HANDLE; | ||
74 | + case MBR_STILL_USED: | ||
75 | + return Code.TABLE_MBR_STILL_USED; | ||
76 | + case MBR_ALREADY_IN_GRP: | ||
77 | + return Code.TABLE_MBR_ALREADY_IN_GRP; | ||
78 | + case MBR_NOT_IN_GRP: | ||
79 | + return Code.TABLE_MBR_NOT_IN_GRP; | ||
80 | + case INVALID_GRP_HANDLE: | ||
81 | + return Code.TABLE_INVALID_GRP_HANDLE; | ||
82 | + case GRP_STILL_USED: | ||
83 | + return Code.TABLE_GRP_STILL_USED; | ||
84 | + case EMPTY_GRP: | ||
85 | + return Code.TABLE_EMPTY_GRP; | ||
86 | + case DUPLICATE_ENTRY: | ||
87 | + return Code.TABLE_DUPLICATE_ENTRY; | ||
88 | + case BAD_MATCH_KEY: | ||
89 | + return Code.TABLE_BAD_MATCH_KEY; | ||
90 | + case INVALID_METER_OPERATION: | ||
91 | + return Code.TABLE_INVALID_METER_OPERATION; | ||
92 | + case DEFAULT_ACTION_IS_CONST: | ||
93 | + return Code.TABLE_DEFAULT_ACTION_IS_CONST; | ||
94 | + case DEFAULT_ENTRY_IS_CONST: | ||
95 | + return Code.TABLE_DEFAULT_ENTRY_IS_CONST; | ||
96 | + case ERROR: | ||
97 | + return Code.TABLE_GENERAL_ERROR; | ||
98 | + default: | ||
99 | + return Code.TABLE_UNKNOWN_ERROR; | ||
100 | + } | ||
101 | + } else if (e instanceof InvalidCounterOperation) { | ||
102 | + InvalidCounterOperation t = (InvalidCounterOperation) e; | ||
103 | + switch (t.getCode()) { | ||
104 | + case INVALID_COUNTER_NAME: | ||
105 | + return Code.COUNTER_INVALID_NAME; | ||
106 | + case INVALID_INDEX: | ||
107 | + return Code.COUNTER_INVALID_INDEX; | ||
108 | + case ERROR: | ||
109 | + return Code.COUNTER_ERROR_GENERAL; | ||
110 | + default: | ||
111 | + return Code.COUNTER_ERROR_UNKNOWN; | ||
112 | + } | ||
113 | + } else if (e instanceof InvalidDevMgrOperation) { | ||
114 | + InvalidDevMgrOperation t = (InvalidDevMgrOperation) e; | ||
115 | + switch (t.getCode()) { | ||
116 | + case ERROR: | ||
117 | + return Code.DEV_MGR_ERROR_GENERAL; | ||
118 | + default: | ||
119 | + return Code.DEV_MGR_UNKNOWN; | ||
120 | + } | ||
121 | + } else if (e instanceof InvalidSwapOperation) { | ||
122 | + InvalidSwapOperation t = (InvalidSwapOperation) e; | ||
123 | + switch (t.getCode()) { | ||
124 | + case CONFIG_SWAP_DISABLED: | ||
125 | + return Code.SWAP_CONFIG_DISABLED; | ||
126 | + case ONGOING_SWAP: | ||
127 | + return Code.SWAP_ONGOING; | ||
128 | + case NO_ONGOING_SWAP: | ||
129 | + return Code.SWAP_NO_ONGOING; | ||
130 | + default: | ||
131 | + return Code.SWAP_ERROR_UKNOWN; | ||
132 | + } | ||
133 | + } else if (e instanceof InvalidMeterOperation) { | ||
134 | + // TODO | ||
135 | + throw new ParserException(e.toString()); | ||
136 | + } else if (e instanceof InvalidRegisterOperation) { | ||
137 | + // TODO | ||
138 | + throw new ParserException(e.toString()); | ||
139 | + } else if (e instanceof InvalidLearnOperation) { | ||
140 | + // TODO | ||
141 | + throw new ParserException(e.toString()); | ||
142 | + } else if (e instanceof InvalidMcOperation) { | ||
143 | + // TODO | ||
144 | + throw new ParserException(e.toString()); | ||
145 | + } else { | ||
146 | + throw new ParserException(e.toString()); | ||
147 | + } | ||
148 | + } | ||
149 | + | ||
150 | + private static class ParserException extends Exception { | ||
151 | + | ||
152 | + private String codeString; | ||
153 | + | ||
154 | + public ParserException(String codeString) { | ||
155 | + this.codeString = codeString; | ||
156 | + } | ||
157 | + } | ||
158 | +} |
This diff is collapsed. Click to expand it.
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.ctl; | ||
18 | + | ||
19 | +import org.apache.felix.scr.annotations.Activate; | ||
20 | +import org.apache.felix.scr.annotations.Component; | ||
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.apache.felix.scr.annotations.Reference; | ||
23 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
24 | +import org.apache.felix.scr.annotations.Service; | ||
25 | +import org.onlab.util.KryoNamespace; | ||
26 | +import org.onosproject.bmv2.api.context.Bmv2DeviceContext; | ||
27 | +import org.onosproject.bmv2.api.context.Bmv2FlowRuleTranslator; | ||
28 | +import org.onosproject.bmv2.api.service.Bmv2DeviceContextService; | ||
29 | +import org.onosproject.bmv2.api.service.Bmv2Controller; | ||
30 | +import org.onosproject.bmv2.api.runtime.Bmv2DeviceAgent; | ||
31 | +import org.onosproject.bmv2.api.runtime.Bmv2ExactMatchParam; | ||
32 | +import org.onosproject.bmv2.api.runtime.Bmv2FlowRuleWrapper; | ||
33 | +import org.onosproject.bmv2.api.runtime.Bmv2LpmMatchParam; | ||
34 | +import org.onosproject.bmv2.api.runtime.Bmv2MatchKey; | ||
35 | +import org.onosproject.bmv2.api.runtime.Bmv2ParsedTableEntry; | ||
36 | +import org.onosproject.bmv2.api.runtime.Bmv2RuntimeException; | ||
37 | +import org.onosproject.bmv2.api.runtime.Bmv2TableEntryReference; | ||
38 | +import org.onosproject.bmv2.api.service.Bmv2TableEntryService; | ||
39 | +import org.onosproject.bmv2.api.runtime.Bmv2TernaryMatchParam; | ||
40 | +import org.onosproject.bmv2.api.runtime.Bmv2ValidMatchParam; | ||
41 | +import org.onosproject.net.DeviceId; | ||
42 | +import org.onosproject.store.serializers.KryoNamespaces; | ||
43 | +import org.onosproject.store.service.EventuallyConsistentMap; | ||
44 | +import org.onosproject.store.service.StorageService; | ||
45 | +import org.onosproject.store.service.WallClockTimestamp; | ||
46 | +import org.slf4j.Logger; | ||
47 | +import org.slf4j.LoggerFactory; | ||
48 | + | ||
49 | +import java.util.Collections; | ||
50 | +import java.util.List; | ||
51 | + | ||
52 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
53 | + | ||
54 | +/** | ||
55 | + * Implementation of the Bmv2TableEntryService. | ||
56 | + */ | ||
57 | +@Component(immediate = true) | ||
58 | +@Service | ||
59 | +public class Bmv2TableEntryServiceImpl implements Bmv2TableEntryService { | ||
60 | + | ||
61 | + private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
62 | + | ||
63 | + private final Bmv2FlowRuleTranslator translator = new Bmv2FlowRuleTranslatorImpl(); | ||
64 | + | ||
65 | + private EventuallyConsistentMap<Bmv2TableEntryReference, Bmv2FlowRuleWrapper> flowRules; | ||
66 | + | ||
67 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
68 | + protected StorageService storageService; | ||
69 | + | ||
70 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
71 | + protected Bmv2Controller controller; | ||
72 | + | ||
73 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
74 | + protected Bmv2DeviceContextService contextService; | ||
75 | + | ||
76 | + | ||
77 | + @Activate | ||
78 | + public void activate() { | ||
79 | + KryoNamespace kryo = new KryoNamespace.Builder() | ||
80 | + .register(KryoNamespaces.API) | ||
81 | + .register(Bmv2TableEntryReference.class) | ||
82 | + .register(Bmv2MatchKey.class) | ||
83 | + .register(Bmv2ExactMatchParam.class) | ||
84 | + .register(Bmv2TernaryMatchParam.class) | ||
85 | + .register(Bmv2LpmMatchParam.class) | ||
86 | + .register(Bmv2ValidMatchParam.class) | ||
87 | + .register(Bmv2FlowRuleWrapper.class) | ||
88 | + .build(); | ||
89 | + | ||
90 | + flowRules = storageService.<Bmv2TableEntryReference, Bmv2FlowRuleWrapper>eventuallyConsistentMapBuilder() | ||
91 | + .withSerializer(kryo) | ||
92 | + .withTimestampProvider((k, v) -> new WallClockTimestamp()) | ||
93 | + .withName("onos-bmv2-flowrules") | ||
94 | + .build(); | ||
95 | + | ||
96 | + log.info("Started"); | ||
97 | + } | ||
98 | + | ||
99 | + @Deactivate | ||
100 | + public void deactivate() { | ||
101 | + log.info("Stopped"); | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public Bmv2FlowRuleTranslator getFlowRuleTranslator() { | ||
106 | + return translator; | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public List<Bmv2ParsedTableEntry> getTableEntries(DeviceId deviceId, String tableName) { | ||
111 | + try { | ||
112 | + Bmv2DeviceContext context = contextService.getContext(deviceId); | ||
113 | + if (context == null) { | ||
114 | + log.warn("Unable to get table entries, found null context for {}", deviceId); | ||
115 | + return Collections.emptyList(); | ||
116 | + } | ||
117 | + Bmv2DeviceAgent agent = controller.getAgent(deviceId); | ||
118 | + String tableDump = agent.dumpTable(tableName); | ||
119 | + return Bmv2TableDumpParser.parse(tableDump, context.configuration()); | ||
120 | + } catch (Bmv2RuntimeException e) { | ||
121 | + log.warn("Unable to get table entries for {}: {}", deviceId, e.explain()); | ||
122 | + return Collections.emptyList(); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | + @Override | ||
127 | + public Bmv2FlowRuleWrapper lookupEntryReference(Bmv2TableEntryReference entryRef) { | ||
128 | + checkNotNull(entryRef, "table entry reference cannot be null"); | ||
129 | + return flowRules.get(entryRef); | ||
130 | + } | ||
131 | + | ||
132 | + @Override | ||
133 | + public void bindEntryReference(Bmv2TableEntryReference entryRef, Bmv2FlowRuleWrapper rule) { | ||
134 | + checkNotNull(entryRef, "table entry reference cannot be null"); | ||
135 | + checkNotNull(rule, "bmv2 flow rule cannot be null"); | ||
136 | + flowRules.put(entryRef, rule); | ||
137 | + } | ||
138 | + | ||
139 | + @Override | ||
140 | + public void unbindEntryReference(Bmv2TableEntryReference entryRef) { | ||
141 | + checkNotNull(entryRef, "table entry reference cannot be null"); | ||
142 | + flowRules.remove(entryRef); | ||
143 | + } | ||
144 | +} |
... | @@ -218,8 +218,8 @@ public final class SafeThriftClient { | ... | @@ -218,8 +218,8 @@ public final class SafeThriftClient { |
218 | // Thrift transport layer is not thread-safe (it's a wrapper on a socket), hence we need locking. | 218 | // Thrift transport layer is not thread-safe (it's a wrapper on a socket), hence we need locking. |
219 | synchronized (transport) { | 219 | synchronized (transport) { |
220 | 220 | ||
221 | - LOG.debug("Invoking client method... > method={}, fromThread={}", | 221 | + LOG.debug("Invoking method... > fromThread={}, method={}, args={}", |
222 | - method.getName(), Thread.currentThread().getId()); | 222 | + Thread.currentThread().getId(), method.getName(), args); |
223 | 223 | ||
224 | try { | 224 | try { |
225 | 225 | ||
... | @@ -235,15 +235,13 @@ public final class SafeThriftClient { | ... | @@ -235,15 +235,13 @@ public final class SafeThriftClient { |
235 | // If here, transport has been successfully open, hence new exceptions will be thrown. | 235 | // If here, transport has been successfully open, hence new exceptions will be thrown. |
236 | return method.invoke(baseClient, args); | 236 | return method.invoke(baseClient, args); |
237 | } catch (InvocationTargetException e1) { | 237 | } catch (InvocationTargetException e1) { |
238 | - LOG.debug("Exception while invoking client method: {} > method={}, fromThread={}", | 238 | + LOG.debug("Exception: {}", e1.getTargetException()); |
239 | - e1, method.getName(), Thread.currentThread().getId()); | ||
240 | throw e1.getTargetException(); | 239 | throw e1.getTargetException(); |
241 | } | 240 | } |
242 | } | 241 | } |
243 | } | 242 | } |
244 | // Target exception is neither a TTransportException nor a restartable cause. | 243 | // Target exception is neither a TTransportException nor a restartable cause. |
245 | - LOG.debug("Exception while invoking client method: {} > method={}, fromThread={}", | 244 | + LOG.debug("Exception: {}", e.getTargetException()); |
246 | - e, method.getName(), Thread.currentThread().getId()); | ||
247 | throw e.getTargetException(); | 245 | throw e.getTargetException(); |
248 | } | 246 | } |
249 | } | 247 | } | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2014-2016 Open Networking Laboratory | 2 | + * Copyright 2016-present Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. | ... | ... |
This diff is collapsed. Click to expand it.
protocols/bmv2/ctl/src/test/java/org/onosproject/bmv2/ctl/Bmv2FlowRuleTranslatorImplTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bmv2.ctl; | ||
18 | + | ||
19 | +import com.google.common.testing.EqualsTester; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.MacAddress; | ||
22 | +import org.onosproject.bmv2.api.context.Bmv2Configuration; | ||
23 | +import org.onosproject.bmv2.api.context.Bmv2DeviceContext; | ||
24 | +import org.onosproject.bmv2.api.context.Bmv2FlowRuleTranslator; | ||
25 | +import org.onosproject.bmv2.api.context.Bmv2Interpreter; | ||
26 | +import org.onosproject.bmv2.api.runtime.Bmv2TableEntry; | ||
27 | +import org.onosproject.bmv2.api.runtime.Bmv2TernaryMatchParam; | ||
28 | +import org.onosproject.core.ApplicationId; | ||
29 | +import org.onosproject.core.DefaultApplicationId; | ||
30 | +import org.onosproject.net.DeviceId; | ||
31 | +import org.onosproject.net.PortNumber; | ||
32 | +import org.onosproject.net.flow.DefaultFlowRule; | ||
33 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
34 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
35 | +import org.onosproject.net.flow.FlowRule; | ||
36 | +import org.onosproject.net.flow.TrafficSelector; | ||
37 | +import org.onosproject.net.flow.TrafficTreatment; | ||
38 | + | ||
39 | +import java.util.Random; | ||
40 | + | ||
41 | +import static org.hamcrest.CoreMatchers.equalTo; | ||
42 | +import static org.hamcrest.CoreMatchers.is; | ||
43 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
44 | +import static org.onosproject.bmv2.ctl.Bmv2DefaultInterpreterImpl.TABLE0; | ||
45 | + | ||
46 | +/** | ||
47 | + * Tests for {@link Bmv2FlowRuleTranslatorImpl}. | ||
48 | + */ | ||
49 | +public class Bmv2FlowRuleTranslatorImplTest { | ||
50 | + | ||
51 | + private Random random = new Random(); | ||
52 | + private Bmv2Configuration configuration = Bmv2DeviceContextServiceImpl.loadDefaultConfiguration(); | ||
53 | + private Bmv2Interpreter interpreter = new Bmv2DefaultInterpreterImpl(); | ||
54 | + private Bmv2DeviceContext context = new Bmv2DeviceContext(configuration, interpreter); | ||
55 | + private Bmv2FlowRuleTranslator translator = new Bmv2FlowRuleTranslatorImpl(); | ||
56 | + | ||
57 | + @Test | ||
58 | + public void testTranslate() throws Exception { | ||
59 | + | ||
60 | + DeviceId deviceId = DeviceId.NONE; | ||
61 | + ApplicationId appId = new DefaultApplicationId(1, "test"); | ||
62 | + int tableId = 0; | ||
63 | + MacAddress ethDstMac = MacAddress.valueOf(random.nextLong()); | ||
64 | + MacAddress ethSrcMac = MacAddress.valueOf(random.nextLong()); | ||
65 | + short ethType = (short) (0x0000FFFF & random.nextInt()); | ||
66 | + short outPort = (short) random.nextInt(65); | ||
67 | + short inPort = (short) random.nextInt(65); | ||
68 | + int timeout = random.nextInt(100); | ||
69 | + int priority = random.nextInt(100); | ||
70 | + | ||
71 | + TrafficSelector matchInPort1 = DefaultTrafficSelector | ||
72 | + .builder() | ||
73 | + .matchInPort(PortNumber.portNumber(inPort)) | ||
74 | + .matchEthDst(ethDstMac) | ||
75 | + .matchEthSrc(ethSrcMac) | ||
76 | + .matchEthType(ethType) | ||
77 | + .build(); | ||
78 | + | ||
79 | + TrafficTreatment outPort2 = DefaultTrafficTreatment | ||
80 | + .builder() | ||
81 | + .setOutput(PortNumber.portNumber(outPort)) | ||
82 | + .build(); | ||
83 | + | ||
84 | + FlowRule rule1 = DefaultFlowRule.builder() | ||
85 | + .forDevice(deviceId) | ||
86 | + .forTable(tableId) | ||
87 | + .fromApp(appId) | ||
88 | + .withSelector(matchInPort1) | ||
89 | + .withTreatment(outPort2) | ||
90 | + .makeTemporary(timeout) | ||
91 | + .withPriority(priority) | ||
92 | + .build(); | ||
93 | + | ||
94 | + FlowRule rule2 = DefaultFlowRule.builder() | ||
95 | + .forDevice(deviceId) | ||
96 | + .forTable(tableId) | ||
97 | + .fromApp(appId) | ||
98 | + .withSelector(matchInPort1) | ||
99 | + .withTreatment(outPort2) | ||
100 | + .makeTemporary(timeout) | ||
101 | + .withPriority(priority) | ||
102 | + .build(); | ||
103 | + | ||
104 | + Bmv2TableEntry entry1 = translator.translate(rule1, context); | ||
105 | + Bmv2TableEntry entry2 = translator.translate(rule1, context); | ||
106 | + | ||
107 | + // check equality, i.e. same rules must produce same entries | ||
108 | + new EqualsTester() | ||
109 | + .addEqualityGroup(rule1, rule2) | ||
110 | + .addEqualityGroup(entry1, entry2) | ||
111 | + .testEquals(); | ||
112 | + | ||
113 | + int numMatchParams = configuration.table(TABLE0).keys().size(); | ||
114 | + // parse values stored in entry1 | ||
115 | + Bmv2TernaryMatchParam inPortParam = (Bmv2TernaryMatchParam) entry1.matchKey().matchParams().get(0); | ||
116 | + Bmv2TernaryMatchParam ethDstParam = (Bmv2TernaryMatchParam) entry1.matchKey().matchParams().get(1); | ||
117 | + Bmv2TernaryMatchParam ethSrcParam = (Bmv2TernaryMatchParam) entry1.matchKey().matchParams().get(2); | ||
118 | + Bmv2TernaryMatchParam ethTypeParam = (Bmv2TernaryMatchParam) entry1.matchKey().matchParams().get(3); | ||
119 | + double expectedTimeout = (double) (configuration.table(TABLE0).hasTimeouts() ? rule1.timeout() : -1); | ||
120 | + | ||
121 | + // check that the number of parameters in the entry is the same as the number of table keys | ||
122 | + assertThat("Incorrect number of match parameters", | ||
123 | + entry1.matchKey().matchParams().size(), is(equalTo(numMatchParams))); | ||
124 | + | ||
125 | + // check that values stored in entry are the same used for the flow rule | ||
126 | + assertThat("Incorrect inPort match param value", | ||
127 | + inPortParam.value().asReadOnlyBuffer().getShort(), is(equalTo(inPort))); | ||
128 | + assertThat("Incorrect ethDestMac match param value", | ||
129 | + ethDstParam.value().asArray(), is(equalTo(ethDstMac.toBytes()))); | ||
130 | + assertThat("Incorrect ethSrcMac match param value", | ||
131 | + ethSrcParam.value().asArray(), is(equalTo(ethSrcMac.toBytes()))); | ||
132 | + assertThat("Incorrect ethType match param value", | ||
133 | + ethTypeParam.value().asReadOnlyBuffer().getShort(), is(equalTo(ethType))); | ||
134 | + assertThat("Incorrect priority value", | ||
135 | + entry1.priority(), is(equalTo(Integer.MAX_VALUE - rule1.priority()))); | ||
136 | + assertThat("Incorrect timeout value", | ||
137 | + entry1.timeout(), is(equalTo(expectedTimeout))); | ||
138 | + | ||
139 | + } | ||
140 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -14,35 +14,36 @@ | ... | @@ -14,35 +14,36 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | -package org.onosproject.bmv2.api.model; | 17 | +package org.onosproject.bmv2.ctl; |
18 | 18 | ||
19 | import org.junit.Test; | 19 | import org.junit.Test; |
20 | -import org.onosproject.bmv2.ctl.Bmv2TableDumpParser; | 20 | +import org.onosproject.bmv2.api.context.Bmv2Configuration; |
21 | - | 21 | +import org.onosproject.bmv2.api.runtime.Bmv2ParsedTableEntry; |
22 | + | ||
23 | +import java.io.IOException; | ||
24 | +import java.net.URISyntaxException; | ||
25 | +import java.nio.charset.Charset; | ||
26 | +import java.nio.file.Files; | ||
27 | +import java.nio.file.Paths; | ||
22 | import java.util.List; | 28 | import java.util.List; |
23 | 29 | ||
24 | import static org.hamcrest.MatcherAssert.assertThat; | 30 | import static org.hamcrest.MatcherAssert.assertThat; |
25 | -import static org.hamcrest.core.Is.is; | 31 | +import static org.hamcrest.Matchers.equalTo; |
26 | -import static org.hamcrest.core.IsEqual.equalTo; | ||
27 | 32 | ||
28 | public class Bmv2TableDumpParserTest { | 33 | public class Bmv2TableDumpParserTest { |
29 | 34 | ||
30 | - @Test | 35 | + private Bmv2Configuration configuration = Bmv2DeviceContextServiceImpl.loadDefaultConfiguration(); |
31 | - public void testParse() throws Exception, Bmv2TableDumpParser.Bmv2TableDumpParserException { | ||
32 | - | ||
33 | - String text = | ||
34 | - "0: 0000 000000000000 000000000000 &&& 0000000000000000000000000000 => send_to_cpu -\n" + | ||
35 | - "1: 0000 000000000000 000000000000 &&& 0000000000000000000000000000 => send_to_cpu -\n" + | ||
36 | - "2: 0000 000000000000 000000000000 &&& 0000000000000000000000000000 => send_to_cpu -\n" + | ||
37 | - "3: 0000 000000000000 000000000000 &&& 0000000000000000000000000000 => send_to_cpu -"; | ||
38 | 36 | ||
39 | - Bmv2TableDumpParser parser = new Bmv2TableDumpParser(); | 37 | + @Test |
40 | - | 38 | + public void testParse() throws Exception { |
41 | - List<Long> result = parser.getEntryIds(text); | 39 | + String text = readFile(); |
40 | + List<Bmv2ParsedTableEntry> result = Bmv2TableDumpParser.parse(text, configuration); | ||
41 | + assertThat(result.size(), equalTo(10)); | ||
42 | + } | ||
42 | 43 | ||
43 | - assertThat("invalid parsed values", result.get(0), is(equalTo(0L))); | 44 | + private String readFile() |
44 | - assertThat("invalid parsed values", result.get(1), is(equalTo(1L))); | 45 | + throws IOException, URISyntaxException { |
45 | - assertThat("invalid parsed values", result.get(2), is(equalTo(2L))); | 46 | + byte[] encoded = Files.readAllBytes(Paths.get(this.getClass().getResource("/tabledump.txt").toURI())); |
46 | - assertThat("invalid parsed values", result.get(3), is(equalTo(3L))); | 47 | + return new String(encoded, Charset.defaultCharset()); |
47 | } | 48 | } |
48 | } | 49 | } | ... | ... |
1 | +0: 0000 000000000000 000000000000 0806 &&& 0000000000000000000000000000ffff => send_to_cpu - | ||
2 | +1: 0000 000000000000 000000000000 0800 &&& 0000000000000000000000000000ffff => send_to_cpu - | ||
3 | +2: 0000 000000000000 000000000000 88cc &&& 0000000000000000000000000000ffff => send_to_cpu - | ||
4 | +3: 0000 000000000000 000000000000 8942 &&& 0000000000000000000000000000ffff => send_to_cpu - | ||
5 | +4: 0001 000400000001 000400000000 0000 &&& ffffffffffffffffffffffffffff0000 => set_egress_port - 2, | ||
6 | +5: 0002 000400000000 000400000001 0000 &&& ffffffffffffffffffffffffffff0000 => set_egress_port - 1, | ||
7 | +51539607552: 0001 0000 => set_egress_port - 1, | ||
8 | +51539607553: 0001 0002 => set_egress_port - 3, | ||
9 | +51539607554: 0001 0001 => set_egress_port - 2, | ||
10 | +51539607555: 0001 0003 => set_egress_port - 4, | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
1 | -/* | ||
2 | - * Copyright 2016-present Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -package org.onosproject.bmv2.ctl; | ||
18 | - | ||
19 | -import com.google.common.collect.Lists; | ||
20 | -import org.apache.commons.lang3.tuple.Pair; | ||
21 | - | ||
22 | -import java.util.List; | ||
23 | -import java.util.regex.Matcher; | ||
24 | -import java.util.regex.Pattern; | ||
25 | -import java.util.stream.Collectors; | ||
26 | - | ||
27 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
28 | - | ||
29 | -/** | ||
30 | - * String parser for the BMv2 table dump. | ||
31 | - */ | ||
32 | -public class Bmv2TableDumpParser { | ||
33 | - | ||
34 | - /* | ||
35 | - Example of BMv2 table dump: | ||
36 | - 0: 0000 000000000000 000000000000 0806 &&& 0000000000000000000000000000ffff => send_to_cpu - | ||
37 | - | ||
38 | - For each entry, we want to match the id and all the rest. | ||
39 | - */ | ||
40 | - private static final String ENTRY_PATTERN_STRING = "(\\d+):(.+)"; | ||
41 | - private static final Pattern ENTRY_PATTERN = Pattern.compile(ENTRY_PATTERN_STRING); | ||
42 | - | ||
43 | - /** | ||
44 | - * Returns a list of entry Ids for the given table dump. | ||
45 | - * | ||
46 | - * @param tableDump a string value | ||
47 | - * @return a list of long values | ||
48 | - * @throws Bmv2TableDumpParserException if dump can't be parsed | ||
49 | - */ | ||
50 | - public List<Long> getEntryIds(String tableDump) throws Bmv2TableDumpParserException { | ||
51 | - return parse(tableDump).stream().map(Pair::getKey).collect(Collectors.toList()); | ||
52 | - } | ||
53 | - | ||
54 | - private List<Pair<Long, String>> parse(String tableDump) throws Bmv2TableDumpParserException { | ||
55 | - checkNotNull(tableDump, "tableDump cannot be null"); | ||
56 | - | ||
57 | - List<Pair<Long, String>> results = Lists.newArrayList(); | ||
58 | - | ||
59 | - // TODO: consider caching parser results for speed. | ||
60 | - | ||
61 | - Matcher matcher = ENTRY_PATTERN.matcher(tableDump); | ||
62 | - | ||
63 | - while (matcher.find()) { | ||
64 | - String entryString = matcher.group(1); | ||
65 | - if (entryString == null) { | ||
66 | - throw new Bmv2TableDumpParserException("Unable to parse entry for string: " + matcher.group()); | ||
67 | - } | ||
68 | - Long entryId = -1L; | ||
69 | - try { | ||
70 | - entryId = Long.valueOf(entryString.trim()); | ||
71 | - } catch (NumberFormatException e) { | ||
72 | - throw new Bmv2TableDumpParserException("Unable to parse entry id for string: " + matcher.group()); | ||
73 | - } | ||
74 | - String allTheRest = matcher.group(2); | ||
75 | - if (allTheRest == null) { | ||
76 | - throw new Bmv2TableDumpParserException("Unable to parse entry for string: " + matcher.group()); | ||
77 | - } | ||
78 | - results.add(Pair.of(entryId, allTheRest)); | ||
79 | - } | ||
80 | - | ||
81 | - return results; | ||
82 | - } | ||
83 | - | ||
84 | - public class Bmv2TableDumpParserException extends Throwable { | ||
85 | - public Bmv2TableDumpParserException(String msg) { | ||
86 | - super(msg); | ||
87 | - } | ||
88 | - } | ||
89 | -} |
protocols/bmv2/thrift-api/pom.xml
0 → 100644
This diff is collapsed. Click to expand it.
File moved
... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
18 | set -e | 18 | set -e |
19 | 19 | ||
20 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | 20 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
21 | -ns="org.p4.bmv2.thrift" | 21 | +ns="org.onosproject.bmv2.thriftapi" |
22 | 22 | ||
23 | # add java namespace at beginning of file | 23 | # add java namespace at beginning of file |
24 | for f in ${basedir}/*.thrift | 24 | for f in ${basedir}/*.thrift | ... | ... |
... | @@ -46,7 +46,7 @@ | ... | @@ -46,7 +46,7 @@ |
46 | <module>lldpcommon</module> | 46 | <module>lldpcommon</module> |
47 | <module>lldp</module> | 47 | <module>lldp</module> |
48 | <module>netcfglinks</module> | 48 | <module>netcfglinks</module> |
49 | - <module>bmv2</module> | 49 | + <!--<module>bmv2</module>--> |
50 | <module>isis</module> | 50 | <module>isis</module> |
51 | </modules> | 51 | </modules> |
52 | 52 | ... | ... |
... | @@ -73,6 +73,24 @@ public final class ImmutableByteSequence { | ... | @@ -73,6 +73,24 @@ public final class ImmutableByteSequence { |
73 | } | 73 | } |
74 | 74 | ||
75 | /** | 75 | /** |
76 | + * Creates a new immutable byte sequence with the same content and order of | ||
77 | + * the passed byte array, from/to the given indexes (inclusive). | ||
78 | + * | ||
79 | + * @param original a byte array value | ||
80 | + * @return a new immutable byte sequence | ||
81 | + */ | ||
82 | + public static ImmutableByteSequence copyFrom(byte[] original, int fromIdx, int toIdx) { | ||
83 | + checkArgument(original != null && original.length > 0, | ||
84 | + "Cannot copy from an empty or null array"); | ||
85 | + checkArgument(toIdx >= fromIdx && toIdx < original.length, "invalid indexes"); | ||
86 | + ByteBuffer buffer = ByteBuffer.allocate((toIdx - fromIdx) + 1); | ||
87 | + for (int i = fromIdx; i <= toIdx; i++) { | ||
88 | + buffer.put(original[i]); | ||
89 | + } | ||
90 | + return new ImmutableByteSequence(buffer); | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
76 | * Creates a new immutable byte sequence copying bytes from the given | 94 | * Creates a new immutable byte sequence copying bytes from the given |
77 | * ByteBuffer {@link ByteBuffer}. If the byte buffer order is not big-endian | 95 | * ByteBuffer {@link ByteBuffer}. If the byte buffer order is not big-endian |
78 | * bytes will be copied in reverse order. | 96 | * bytes will be copied in reverse order. | ... | ... |
-
Please register or login to post a comment