Jonathan Hart
Committed by Gerrit Code Review

Implemented the extension framework for selectors.

Change-Id: I577900141889fc70ca54e96cd5d54cfd5194b05d
Showing 26 changed files with 578 additions and 92 deletions
1 +/*
2 + * Copyright 2015 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.net.behaviour;
18 +
19 +import com.google.common.annotations.Beta;
20 +import org.onosproject.net.driver.HandlerBehaviour;
21 +import org.onosproject.net.flow.criteria.ExtensionSelector;
22 +import org.onosproject.net.flow.criteria.ExtensionSelectorType;
23 +
24 +/**
25 + * Provides access to the extension selectors implemented by this driver.
26 + */
27 +@Beta
28 +public interface ExtensionSelectorResolver extends HandlerBehaviour {
29 +
30 + /**
31 + * Gets an extension selector instance of the specified type, if supported
32 + * by the driver.
33 + *
34 + * @param type type of extension to get
35 + * @return extension selector
36 + * @throws UnsupportedOperationException if the extension type is not
37 + * supported by this driver
38 + */
39 + ExtensionSelector getExtensionSelector(ExtensionSelectorType type);
40 +}
...@@ -14,22 +14,25 @@ ...@@ -14,22 +14,25 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.net.flow.instructions; 17 +package org.onosproject.net.flow;
18 +
19 +import org.onosproject.net.flow.instructions.ExtensionPropertyException;
18 20
19 import java.lang.reflect.Field; 21 import java.lang.reflect.Field;
20 import java.util.ArrayList; 22 import java.util.ArrayList;
21 import java.util.List; 23 import java.util.List;
22 24
23 /** 25 /**
24 - * Abstract implementation of the set/get property methods of ExtensionInstruction. 26 + * Abstract implementation of the set/get property methods of Extension.
25 */ 27 */
26 -public abstract class AbstractExtensionTreatment implements ExtensionTreatment { 28 +public abstract class AbstractExtension implements Extension {
27 29
28 private static final String INVALID_KEY = "Invalid property key: "; 30 private static final String INVALID_KEY = "Invalid property key: ";
29 private static final String INVALID_TYPE = "Given type does not match field type: "; 31 private static final String INVALID_TYPE = "Given type does not match field type: ";
30 32
31 @Override 33 @Override
32 - public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { 34 + public <T> void setPropertyValue(String key, T value) throws
35 + ExtensionPropertyException {
33 Class<?> clazz = this.getClass(); 36 Class<?> clazz = this.getClass();
34 try { 37 try {
35 Field field = clazz.getDeclaredField(key); 38 Field field = clazz.getDeclaredField(key);
......
...@@ -15,14 +15,8 @@ ...@@ -15,14 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.flow; 16 package org.onosproject.net.flow;
17 17
18 -import java.util.Collections; 18 +import com.google.common.base.MoreObjects;
19 -import java.util.Comparator; 19 +import com.google.common.collect.ImmutableSet;
20 -import java.util.HashMap;
21 -import java.util.Map;
22 -import java.util.Objects;
23 -import java.util.Set;
24 -import java.util.TreeSet;
25 -
26 import org.onlab.packet.Ip4Address; 20 import org.onlab.packet.Ip4Address;
27 import org.onlab.packet.Ip6Address; 21 import org.onlab.packet.Ip6Address;
28 import org.onlab.packet.IpPrefix; 22 import org.onlab.packet.IpPrefix;
...@@ -30,12 +24,19 @@ import org.onlab.packet.MacAddress; ...@@ -30,12 +24,19 @@ import org.onlab.packet.MacAddress;
30 import org.onlab.packet.MplsLabel; 24 import org.onlab.packet.MplsLabel;
31 import org.onlab.packet.TpPort; 25 import org.onlab.packet.TpPort;
32 import org.onlab.packet.VlanId; 26 import org.onlab.packet.VlanId;
27 +import org.onosproject.net.DeviceId;
33 import org.onosproject.net.PortNumber; 28 import org.onosproject.net.PortNumber;
34 import org.onosproject.net.flow.criteria.Criteria; 29 import org.onosproject.net.flow.criteria.Criteria;
35 import org.onosproject.net.flow.criteria.Criterion; 30 import org.onosproject.net.flow.criteria.Criterion;
31 +import org.onosproject.net.flow.criteria.ExtensionSelector;
36 32
37 -import com.google.common.base.MoreObjects; 33 +import java.util.Collections;
38 -import com.google.common.collect.ImmutableSet; 34 +import java.util.Comparator;
35 +import java.util.HashMap;
36 +import java.util.Map;
37 +import java.util.Objects;
38 +import java.util.Set;
39 +import java.util.TreeSet;
39 40
40 /** 41 /**
41 * Default traffic selector implementation. 42 * Default traffic selector implementation.
...@@ -379,6 +380,12 @@ public final class DefaultTrafficSelector implements TrafficSelector { ...@@ -379,6 +380,12 @@ public final class DefaultTrafficSelector implements TrafficSelector {
379 } 380 }
380 381
381 @Override 382 @Override
383 + public TrafficSelector.Builder extension(ExtensionSelector extensionSelector,
384 + DeviceId deviceId) {
385 + return add(Criteria.extension(extensionSelector, deviceId));
386 + }
387 +
388 + @Override
382 public TrafficSelector build() { 389 public TrafficSelector build() {
383 return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values())); 390 return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values()));
384 } 391 }
......
1 +/*
2 + * Copyright 2015 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.net.flow;
18 +
19 +import org.onosproject.net.flow.instructions.ExtensionPropertyException;
20 +
21 +import java.util.List;
22 +
23 +/**
24 + * An extension to the northbound APIs.
25 + */
26 +public interface Extension {
27 +
28 + /**
29 + * Sets a property on the extension.
30 + *
31 + * @param key property key
32 + * @param value value to set for the given key
33 + * @param <T> class of the value
34 + * @throws ExtensionPropertyException if the given key is not a valid
35 + * property on this extension
36 + */
37 + <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException;
38 +
39 + /**
40 + * Gets a property value of an extension.
41 + *
42 + * @param key property key
43 + * @param <T> class of the value
44 + * @return value of the property
45 + * @throws ExtensionPropertyException if the given key is not a valid
46 + * property on this extension
47 + */
48 + <T> T getPropertyValue(String key) throws ExtensionPropertyException;
49 +
50 + /**
51 + * Gets a list of all properties on the extension.
52 + *
53 + * @return list of properties
54 + */
55 + List<String> getProperties();
56 +
57 + /**
58 + * Serialize the extension to a byte array.
59 + *
60 + * @return byte array
61 + */
62 + byte[] serialize();
63 +
64 + /**
65 + * Deserialize the extension from a byte array. The properties
66 + * of this object will be overwritten with the data in the byte array.
67 + *
68 + * @param data input byte array
69 + */
70 + void deserialize(byte[] data);
71 +}
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.flow; 16 package org.onosproject.net.flow;
17 17
18 -import java.util.Set;
19 -
20 import org.onlab.packet.Ip4Address; 18 import org.onlab.packet.Ip4Address;
21 import org.onlab.packet.Ip6Address; 19 import org.onlab.packet.Ip6Address;
22 import org.onlab.packet.IpPrefix; 20 import org.onlab.packet.IpPrefix;
...@@ -24,8 +22,12 @@ import org.onlab.packet.MacAddress; ...@@ -24,8 +22,12 @@ import org.onlab.packet.MacAddress;
24 import org.onlab.packet.MplsLabel; 22 import org.onlab.packet.MplsLabel;
25 import org.onlab.packet.TpPort; 23 import org.onlab.packet.TpPort;
26 import org.onlab.packet.VlanId; 24 import org.onlab.packet.VlanId;
25 +import org.onosproject.net.DeviceId;
27 import org.onosproject.net.PortNumber; 26 import org.onosproject.net.PortNumber;
28 import org.onosproject.net.flow.criteria.Criterion; 27 import org.onosproject.net.flow.criteria.Criterion;
28 +import org.onosproject.net.flow.criteria.ExtensionSelector;
29 +
30 +import java.util.Set;
29 31
30 /** 32 /**
31 * Abstraction of a slice of network traffic. 33 * Abstraction of a slice of network traffic.
...@@ -427,6 +429,15 @@ public interface TrafficSelector { ...@@ -427,6 +429,15 @@ public interface TrafficSelector {
427 Builder matchArpOp(int arpOp); 429 Builder matchArpOp(int arpOp);
428 430
429 /** 431 /**
432 + * Uses an extension selector.
433 + *
434 + * @param extensionSelector extension selector
435 + * @param deviceId device ID
436 + * @return a selection builder
437 + */
438 + Builder extension(ExtensionSelector extensionSelector, DeviceId deviceId);
439 +
440 + /**
430 * Builds an immutable traffic selector. 441 * Builds an immutable traffic selector.
431 * 442 *
432 * @return traffic selector 443 * @return traffic selector
......
...@@ -23,6 +23,7 @@ import org.onlab.packet.MacAddress; ...@@ -23,6 +23,7 @@ import org.onlab.packet.MacAddress;
23 import org.onlab.packet.MplsLabel; 23 import org.onlab.packet.MplsLabel;
24 import org.onlab.packet.TpPort; 24 import org.onlab.packet.TpPort;
25 import org.onlab.packet.VlanId; 25 import org.onlab.packet.VlanId;
26 +import org.onosproject.net.DeviceId;
26 import org.onosproject.net.IndexedLambda; 27 import org.onosproject.net.IndexedLambda;
27 import org.onosproject.net.Lambda; 28 import org.onosproject.net.Lambda;
28 import org.onosproject.net.OchSignal; 29 import org.onosproject.net.OchSignal;
...@@ -579,6 +580,23 @@ public final class Criteria { ...@@ -579,6 +580,23 @@ public final class Criteria {
579 return new ArpOpCriterion(arpOp, Type.ARP_OP); 580 return new ArpOpCriterion(arpOp, Type.ARP_OP);
580 } 581 }
581 582
583 + /**
584 + * Creates an extension criterion for the specified extension selector.
585 + *
586 + * @param extensionSelector extension selector
587 + * @param deviceId device ID
588 + * @return match criterion
589 + */
590 + public static Criterion extension(ExtensionSelector extensionSelector,
591 + DeviceId deviceId) {
592 + return new ExtensionCriterion(extensionSelector, deviceId);
593 + }
594 +
595 + /**
596 + * Creates a dummy criterion.
597 + *
598 + * @return match criterion
599 + */
582 public static Criterion dummy() { 600 public static Criterion dummy() {
583 return new DummyCriterion(); 601 return new DummyCriterion();
584 } 602 }
......
...@@ -177,6 +177,9 @@ public interface Criterion { ...@@ -177,6 +177,9 @@ public interface Criterion {
177 /** ODU (Optical channel Data Unit) signal type. */ 177 /** ODU (Optical channel Data Unit) signal type. */
178 ODU_SIGTYPE, 178 ODU_SIGTYPE,
179 179
180 + /** Extension criterion. */
181 + EXTENSION,
182 +
180 /** An empty criterion. */ 183 /** An empty criterion. */
181 DUMMY 184 DUMMY
182 } 185 }
......
1 +/*
2 + * Copyright 2015 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.net.flow.criteria;
18 +
19 +import org.onosproject.net.DeviceId;
20 +
21 +import java.util.Objects;
22 +
23 +import static com.google.common.base.MoreObjects.toStringHelper;
24 +
25 +/**
26 + * Criterion for implementing selector extensions.
27 + */
28 +public class ExtensionCriterion implements Criterion {
29 +
30 + private final ExtensionSelector extensionSelector;
31 + private final DeviceId deviceId;
32 +
33 + /**
34 + * Constructor.
35 + *
36 + * @param extensionSelector extension selector
37 + */
38 + public ExtensionCriterion(ExtensionSelector extensionSelector, DeviceId deviceId) {
39 + this.extensionSelector = extensionSelector;
40 + this.deviceId = deviceId;
41 + }
42 +
43 + /**
44 + * Returns the extension selector.
45 + *
46 + * @return extension selector
47 + */
48 + public ExtensionSelector extensionSelector() {
49 + return extensionSelector;
50 + }
51 +
52 + /**
53 + * Returns the device ID.
54 + *
55 + * @return device ID
56 + */
57 + public DeviceId deviceId() {
58 + return deviceId;
59 + }
60 +
61 + @Override
62 + public Type type() {
63 + return Type.EXTENSION;
64 + }
65 +
66 + @Override
67 + public String toString() {
68 + return toStringHelper(type().toString())
69 + .add("extensionSelector", extensionSelector.toString())
70 + .add("deviceId", deviceId)
71 + .toString();
72 + }
73 +
74 + @Override
75 + public int hashCode() {
76 + return Objects.hash(type().ordinal(), extensionSelector, deviceId);
77 + }
78 +
79 + @Override
80 + public boolean equals(Object obj) {
81 + if (this == obj) {
82 + return true;
83 + }
84 + if (obj instanceof ExtensionCriterion) {
85 + ExtensionCriterion that = (ExtensionCriterion) obj;
86 + return Objects.equals(extensionSelector, that.extensionSelector) &&
87 + Objects.equals(deviceId, that.deviceId) &&
88 + Objects.equals(this.type(), that.type());
89 + }
90 + return false;
91 + }
92 +}
1 +/*
2 + * Copyright 2015 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.net.flow.criteria;
18 +
19 +import org.onosproject.net.flow.Extension;
20 +
21 +/**
22 + * An extension for the selector API.
23 + */
24 +public interface ExtensionSelector extends Extension {
25 +
26 + /**
27 + * Gets the type of the extension selector.
28 + *
29 + * @return type
30 + */
31 + ExtensionSelectorType type();
32 +}
1 +/*
2 + * Copyright 2015 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.net.flow.criteria;
18 +
19 +import com.google.common.annotations.Beta;
20 +import com.google.common.base.MoreObjects;
21 +
22 +import java.util.Objects;
23 +
24 +/**
25 + * Type of selector extensions.
26 + */
27 +@Beta
28 +public class ExtensionSelectorType {
29 +
30 + /**
31 + * A list of well-known named extension selector type codes.
32 + * These numbers have no impact on the actual OF type id.
33 + */
34 + public enum ExtensionSelectorTypes {
35 + PLACEHOLDER(0); // TODO remove when actual extensions are added
36 +
37 + private ExtensionSelectorType type;
38 +
39 + /**
40 + * Creates a new named extension selector type.
41 + *
42 + * @param type type code
43 + */
44 + ExtensionSelectorTypes(int type) {
45 + this.type = new ExtensionSelectorType(type);
46 + }
47 +
48 + /**
49 + * Gets the extension type object for this named type code.
50 + *
51 + * @return extension type object
52 + */
53 + public ExtensionSelectorType type() {
54 + return type;
55 + }
56 + }
57 +
58 + private final int type;
59 +
60 + /**
61 + * Creates an extension type with the given int type code.
62 + *
63 + * @param type type code
64 + */
65 + public ExtensionSelectorType(int type) {
66 + this.type = type;
67 + }
68 +
69 + @Override
70 + public int hashCode() {
71 + return Objects.hash(type);
72 + }
73 +
74 + @Override
75 + public boolean equals(Object obj) {
76 + if (this == obj) {
77 + return true;
78 + }
79 + if (obj instanceof ExtensionSelectorType) {
80 + final ExtensionSelectorType that = (ExtensionSelectorType) obj;
81 + return this.type == that.type;
82 + }
83 + return false;
84 + }
85 +
86 + @Override
87 + public String toString() {
88 + return MoreObjects.toStringHelper(ExtensionSelectorType.class)
89 + .add("type", type)
90 + .toString();
91 + }
92 +}
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
16 16
17 package org.onosproject.net.flow.instructions; 17 package org.onosproject.net.flow.instructions;
18 18
19 -import java.util.List; 19 +import org.onosproject.net.flow.Extension;
20 20
21 /** 21 /**
22 - * An extensible instruction type. 22 + * An extenstion for the treatment API.
23 */ 23 */
24 -public interface ExtensionTreatment { 24 +public interface ExtensionTreatment extends Extension {
25 25
26 /** 26 /**
27 * Gets the type of the extension instruction. 27 * Gets the type of the extension instruction.
...@@ -30,49 +30,4 @@ public interface ExtensionTreatment { ...@@ -30,49 +30,4 @@ public interface ExtensionTreatment {
30 */ 30 */
31 ExtensionTreatmentType type(); 31 ExtensionTreatmentType type();
32 32
33 - /**
34 - * Sets a property on the extension instruction.
35 - *
36 - * @param key property key
37 - * @param value value to set for the given key
38 - * @param <T> class of the value
39 - * @throws ExtensionPropertyException if the given key is not a valid
40 - * property on this extension instruction
41 - */
42 - <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException;
43 -
44 - /**
45 - * Gets a property value of an extension instruction.
46 - *
47 - * @param key property key
48 - * @param <T> class of the value
49 - * @return value of the property
50 - * @throws ExtensionPropertyException if the given key is not a valid
51 - * property on this extension instruction
52 - */
53 - <T> T getPropertyValue(String key) throws ExtensionPropertyException;
54 -
55 - /**
56 - * Gets a list of all properties on the extension instruction.
57 - *
58 - * @return list of properties
59 - */
60 - List<String> getProperties();
61 -
62 - /**
63 - * Serialize the extension instruction to a byte array.
64 - *
65 - * @return byte array
66 - */
67 - byte[] serialize();
68 -
69 - /**
70 - * Deserialize the extension instruction from a byte array. The properties
71 - * of this object will be overwritten with the data in the byte array.
72 - *
73 - * @param data input byte array
74 - */
75 - void deserialize(byte[] data);
76 -
77 -
78 } 33 }
......
...@@ -22,7 +22,7 @@ import com.google.common.base.MoreObjects; ...@@ -22,7 +22,7 @@ import com.google.common.base.MoreObjects;
22 import java.util.Objects; 22 import java.util.Objects;
23 23
24 /** 24 /**
25 - * Type of extension instructions. 25 + * Type of treatment extensions.
26 */ 26 */
27 @Beta 27 @Beta
28 public final class ExtensionTreatmentType { 28 public final class ExtensionTreatmentType {
......
...@@ -127,6 +127,7 @@ public final class EncodeCriterionCodecHelper { ...@@ -127,6 +127,7 @@ public final class EncodeCriterionCodecHelper {
127 formatMap.put(Criterion.Type.TCP_FLAGS, new FormatUnknown()); 127 formatMap.put(Criterion.Type.TCP_FLAGS, new FormatUnknown());
128 formatMap.put(Criterion.Type.ACTSET_OUTPUT, new FormatUnknown()); 128 formatMap.put(Criterion.Type.ACTSET_OUTPUT, new FormatUnknown());
129 formatMap.put(Criterion.Type.PACKET_TYPE, new FormatUnknown()); 129 formatMap.put(Criterion.Type.PACKET_TYPE, new FormatUnknown());
130 + formatMap.put(Criterion.Type.EXTENSION, new FormatUnknown());
130 } 131 }
131 132
132 private interface CriterionTypeFormatter { 133 private interface CriterionTypeFormatter {
......
...@@ -436,7 +436,7 @@ public class FlowRuleManager ...@@ -436,7 +436,7 @@ public class FlowRuleManager
436 log.debug("Adding rule in store, but not on switch {}", rule); 436 log.debug("Adding rule in store, but not on switch {}", rule);
437 flowMissing(rule); 437 flowMissing(rule);
438 } catch (Exception e) { 438 } catch (Exception e) {
439 - log.debug("Can't add missing flow rule {}", e.getMessage()); 439 + log.debug("Can't add missing flow rule:", e);
440 continue; 440 continue;
441 } 441 }
442 } 442 }
......
1 +/*
2 + * Copyright 2015 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.driver.extensions;
18 +
19 +import org.onosproject.net.behaviour.ExtensionSelectorResolver;
20 +import org.onosproject.net.driver.AbstractHandlerBehaviour;
21 +import org.onosproject.net.flow.criteria.ExtensionSelector;
22 +import org.onosproject.net.flow.criteria.ExtensionSelectorType;
23 +import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
24 +import org.projectfloodlight.openflow.protocol.OFFactory;
25 +import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
26 +
27 +/**
28 + * Interpreter for Nicira OpenFlow selector extensions.
29 + */
30 +public class NiciraExtensionSelectorInterpreter
31 + extends AbstractHandlerBehaviour
32 + implements ExtensionSelectorInterpreter, ExtensionSelectorResolver {
33 +
34 + @Override
35 + public boolean supported(ExtensionSelectorType extensionSelectorType) {
36 + return false;
37 + }
38 +
39 + @Override
40 + public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
41 + return null;
42 + }
43 +
44 + @Override
45 + public ExtensionSelector mapOxm(OFOxm<?> oxm) {
46 + return null;
47 + }
48 +
49 + @Override
50 + public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
51 + return null;
52 + }
53 +}
...@@ -31,7 +31,7 @@ import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst; ...@@ -31,7 +31,7 @@ import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst;
31 import org.projectfloodlight.openflow.types.IPv4Address; 31 import org.projectfloodlight.openflow.types.IPv4Address;
32 32
33 /** 33 /**
34 - * Interpreter for Nicira OpenFlow extensions. 34 + * Interpreter for Nicira OpenFlow treatment extensions.
35 */ 35 */
36 public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour 36 public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviour
37 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver { 37 implements ExtensionTreatmentInterpreter, ExtensionTreatmentResolver {
......
...@@ -19,7 +19,8 @@ package org.onosproject.driver.extensions; ...@@ -19,7 +19,8 @@ package org.onosproject.driver.extensions;
19 import com.google.common.base.MoreObjects; 19 import com.google.common.base.MoreObjects;
20 import org.onlab.util.KryoNamespace; 20 import org.onlab.util.KryoNamespace;
21 import org.onosproject.net.PortNumber; 21 import org.onosproject.net.PortNumber;
22 -import org.onosproject.net.flow.instructions.AbstractExtensionTreatment; 22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 24 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 import org.onosproject.store.serializers.PortNumberSerializer; 25 import org.onosproject.store.serializers.PortNumberSerializer;
25 26
...@@ -30,7 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -30,7 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
30 /** 31 /**
31 * Nicira resubmit extension instruction. 32 * Nicira resubmit extension instruction.
32 */ 33 */
33 -public class NiciraResubmit extends AbstractExtensionTreatment { 34 +public class NiciraResubmit extends AbstractExtension implements ExtensionTreatment {
34 35
35 private PortNumber inPort; 36 private PortNumber inPort;
36 37
......
...@@ -20,7 +20,8 @@ import com.google.common.base.MoreObjects; ...@@ -20,7 +20,8 @@ import com.google.common.base.MoreObjects;
20 20
21 import org.onlab.util.KryoNamespace; 21 import org.onlab.util.KryoNamespace;
22 import org.onosproject.net.PortNumber; 22 import org.onosproject.net.PortNumber;
23 -import org.onosproject.net.flow.instructions.AbstractExtensionTreatment; 23 +import org.onosproject.net.flow.AbstractExtension;
24 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
24 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 25 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
25 import org.onosproject.store.serializers.PortNumberSerializer; 26 import org.onosproject.store.serializers.PortNumberSerializer;
26 27
...@@ -33,7 +34,8 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -33,7 +34,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
33 /** 34 /**
34 * Nicira resubmit-table extension instruction. 35 * Nicira resubmit-table extension instruction.
35 */ 36 */
36 -public class NiciraResubmitTable extends AbstractExtensionTreatment { 37 +public class NiciraResubmitTable extends AbstractExtension implements
38 + ExtensionTreatment {
37 39
38 //the list of the in port number(PortNumber) and the table(short) 40 //the list of the in port number(PortNumber) and the table(short)
39 private List<Object> inPortAndTable = new ArrayList<Object>(); 41 private List<Object> inPortAndTable = new ArrayList<Object>();
...@@ -109,4 +111,4 @@ public class NiciraResubmitTable extends AbstractExtensionTreatment { ...@@ -109,4 +111,4 @@ public class NiciraResubmitTable extends AbstractExtensionTreatment {
109 return MoreObjects.toStringHelper(getClass()) 111 return MoreObjects.toStringHelper(getClass())
110 .add("inPortAndTable", inPortAndTable).toString(); 112 .add("inPortAndTable", inPortAndTable).toString();
111 } 113 }
112 -}
...\ No newline at end of file ...\ No newline at end of file
114 +}
......
...@@ -16,18 +16,19 @@ ...@@ -16,18 +16,19 @@
16 16
17 package org.onosproject.driver.extensions; 17 package org.onosproject.driver.extensions;
18 18
19 -import java.util.Objects; 19 +import com.google.common.base.MoreObjects;
20 -
21 import org.onlab.util.KryoNamespace; 20 import org.onlab.util.KryoNamespace;
22 -import org.onosproject.net.flow.instructions.AbstractExtensionTreatment; 21 +import org.onosproject.net.flow.AbstractExtension;
22 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 24
25 -import com.google.common.base.MoreObjects; 25 +import java.util.Objects;
26 26
27 /** 27 /**
28 * Nicira set NSH Context header extension instruction. 28 * Nicira set NSH Context header extension instruction.
29 */ 29 */
30 -public class NiciraSetNshContextHeader extends AbstractExtensionTreatment { 30 +public class NiciraSetNshContextHeader extends AbstractExtension implements
31 + ExtensionTreatment {
31 32
32 private int nshCh; 33 private int nshCh;
33 private ExtensionTreatmentType type; 34 private ExtensionTreatmentType type;
......
...@@ -16,18 +16,19 @@ ...@@ -16,18 +16,19 @@
16 16
17 package org.onosproject.driver.extensions; 17 package org.onosproject.driver.extensions;
18 18
19 -import java.util.Objects; 19 +import com.google.common.base.MoreObjects;
20 -
21 import org.onlab.util.KryoNamespace; 20 import org.onlab.util.KryoNamespace;
22 -import org.onosproject.net.flow.instructions.AbstractExtensionTreatment; 21 +import org.onosproject.net.flow.AbstractExtension;
22 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 24
25 -import com.google.common.base.MoreObjects; 25 +import java.util.Objects;
26 26
27 /** 27 /**
28 * Nicira set NSH SI extension instruction. 28 * Nicira set NSH SI extension instruction.
29 */ 29 */
30 -public class NiciraSetNshSi extends AbstractExtensionTreatment { 30 +public class NiciraSetNshSi extends AbstractExtension implements
31 + ExtensionTreatment {
31 32
32 private byte nshSi; 33 private byte nshSi;
33 34
......
...@@ -16,18 +16,19 @@ ...@@ -16,18 +16,19 @@
16 16
17 package org.onosproject.driver.extensions; 17 package org.onosproject.driver.extensions;
18 18
19 -import java.util.Objects; 19 +import com.google.common.base.MoreObjects;
20 -
21 import org.onlab.util.KryoNamespace; 20 import org.onlab.util.KryoNamespace;
22 -import org.onosproject.net.flow.instructions.AbstractExtensionTreatment; 21 +import org.onosproject.net.flow.AbstractExtension;
22 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 24
25 -import com.google.common.base.MoreObjects; 25 +import java.util.Objects;
26 26
27 /** 27 /**
28 * Nicira set NSH SPI extension instruction. 28 * Nicira set NSH SPI extension instruction.
29 */ 29 */
30 -public class NiciraSetNshSpi extends AbstractExtensionTreatment { 30 +public class NiciraSetNshSpi extends AbstractExtension implements
31 + ExtensionTreatment {
31 32
32 private int nshSpi; 33 private int nshSpi;
33 34
......
...@@ -19,7 +19,8 @@ package org.onosproject.driver.extensions; ...@@ -19,7 +19,8 @@ package org.onosproject.driver.extensions;
19 import com.google.common.base.MoreObjects; 19 import com.google.common.base.MoreObjects;
20 import org.onlab.packet.Ip4Address; 20 import org.onlab.packet.Ip4Address;
21 import org.onlab.util.KryoNamespace; 21 import org.onlab.util.KryoNamespace;
22 -import org.onosproject.net.flow.instructions.AbstractExtensionTreatment; 22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 24 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 import org.onosproject.store.serializers.Ip4AddressSerializer; 25 import org.onosproject.store.serializers.Ip4AddressSerializer;
25 26
...@@ -30,7 +31,8 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -30,7 +31,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
30 /** 31 /**
31 * Nicira set tunnel destination extension instruction. 32 * Nicira set tunnel destination extension instruction.
32 */ 33 */
33 -public class NiciraSetTunnelDst extends AbstractExtensionTreatment { 34 +public class NiciraSetTunnelDst extends AbstractExtension implements
35 + ExtensionTreatment {
34 36
35 private Ip4Address tunnelDst; 37 private Ip4Address tunnelDst;
36 38
......
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
36 impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" /> 36 impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" />
37 <behaviour api="org.onosproject.net.behaviour.ExtensionTreatmentResolver" 37 <behaviour api="org.onosproject.net.behaviour.ExtensionTreatmentResolver"
38 impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" /> 38 impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" />
39 + <behaviour api="org.onosproject.openflow.controller.ExtensionSelectorInterpreter"
40 + impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" />
41 + <behaviour api="org.onosproject.net.behaviour.ExtensionSelectorResolver"
42 + impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" />
39 </driver> 43 </driver>
40 <!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB--> 44 <!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB-->
41 <driver name="ovs-netconf" extends="default" 45 <driver name="ovs-netconf" extends="default"
......
1 +/*
2 + * Copyright 2015 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.openflow.controller;
18 +
19 +import com.google.common.annotations.Beta;
20 +import org.onosproject.net.driver.HandlerBehaviour;
21 +import org.onosproject.net.flow.criteria.ExtensionSelector;
22 +import org.onosproject.net.flow.criteria.ExtensionSelectorType;
23 +import org.projectfloodlight.openflow.protocol.OFFactory;
24 +import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
25 +
26 +/**
27 + * Interprets extension selectors and converts them to/from OpenFlow objects.
28 + */
29 +@Beta
30 +public interface ExtensionSelectorInterpreter extends HandlerBehaviour {
31 +
32 + /**
33 + * Returns true if the given extension selector is supported by this
34 + * driver.
35 + *
36 + * @param extensionSelectorType extension selector type
37 + * @return true if the instruction is supported, otherwise false
38 + */
39 + boolean supported(ExtensionSelectorType extensionSelectorType);
40 +
41 + /**
42 + * Maps an extension selector to an OpenFlow OXM.
43 + *
44 + * @param factory OpenFlow factory
45 + * @param extensionSelector extension selector
46 + * @return OpenFlow action
47 + */
48 + OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector);
49 +
50 + /**
51 + * Maps an OpenFlow OXM to an extension selector.
52 + *
53 + * @param oxm OpenFlow OXM
54 + * @return extension selector
55 + */
56 + ExtensionSelector mapOxm(OFOxm<?> oxm);
57 +}
...@@ -20,7 +20,11 @@ import org.onlab.packet.Ip4Prefix; ...@@ -20,7 +20,11 @@ import org.onlab.packet.Ip4Prefix;
20 import org.onlab.packet.Ip6Address; 20 import org.onlab.packet.Ip6Address;
21 import org.onlab.packet.Ip6Prefix; 21 import org.onlab.packet.Ip6Prefix;
22 import org.onlab.packet.VlanId; 22 import org.onlab.packet.VlanId;
23 +import org.onosproject.net.DeviceId;
23 import org.onosproject.net.OchSignal; 24 import org.onosproject.net.OchSignal;
25 +import org.onosproject.net.driver.DefaultDriverData;
26 +import org.onosproject.net.driver.DefaultDriverHandler;
27 +import org.onosproject.net.driver.Driver;
24 import org.onosproject.net.driver.DriverService; 28 import org.onosproject.net.driver.DriverService;
25 import org.onosproject.net.flow.FlowRule; 29 import org.onosproject.net.flow.FlowRule;
26 import org.onosproject.net.flow.TrafficSelector; 30 import org.onosproject.net.flow.TrafficSelector;
...@@ -30,6 +34,8 @@ import org.onosproject.net.flow.criteria.ArpPaCriterion; ...@@ -30,6 +34,8 @@ import org.onosproject.net.flow.criteria.ArpPaCriterion;
30 import org.onosproject.net.flow.criteria.Criterion; 34 import org.onosproject.net.flow.criteria.Criterion;
31 import org.onosproject.net.flow.criteria.EthCriterion; 35 import org.onosproject.net.flow.criteria.EthCriterion;
32 import org.onosproject.net.flow.criteria.EthTypeCriterion; 36 import org.onosproject.net.flow.criteria.EthTypeCriterion;
37 +import org.onosproject.net.flow.criteria.ExtensionCriterion;
38 +import org.onosproject.net.flow.criteria.ExtensionSelector;
33 import org.onosproject.net.flow.criteria.IPCriterion; 39 import org.onosproject.net.flow.criteria.IPCriterion;
34 import org.onosproject.net.flow.criteria.IPDscpCriterion; 40 import org.onosproject.net.flow.criteria.IPDscpCriterion;
35 import org.onosproject.net.flow.criteria.IPEcnCriterion; 41 import org.onosproject.net.flow.criteria.IPEcnCriterion;
...@@ -54,12 +60,14 @@ import org.onosproject.net.flow.criteria.TunnelIdCriterion; ...@@ -54,12 +60,14 @@ import org.onosproject.net.flow.criteria.TunnelIdCriterion;
54 import org.onosproject.net.flow.criteria.UdpPortCriterion; 60 import org.onosproject.net.flow.criteria.UdpPortCriterion;
55 import org.onosproject.net.flow.criteria.VlanIdCriterion; 61 import org.onosproject.net.flow.criteria.VlanIdCriterion;
56 import org.onosproject.net.flow.criteria.VlanPcpCriterion; 62 import org.onosproject.net.flow.criteria.VlanPcpCriterion;
63 +import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
57 import org.projectfloodlight.openflow.protocol.OFFactory; 64 import org.projectfloodlight.openflow.protocol.OFFactory;
58 import org.projectfloodlight.openflow.protocol.OFFlowAdd; 65 import org.projectfloodlight.openflow.protocol.OFFlowAdd;
59 import org.projectfloodlight.openflow.protocol.OFFlowDelete; 66 import org.projectfloodlight.openflow.protocol.OFFlowDelete;
60 import org.projectfloodlight.openflow.protocol.OFFlowMod; 67 import org.projectfloodlight.openflow.protocol.OFFlowMod;
61 import org.projectfloodlight.openflow.protocol.match.Match; 68 import org.projectfloodlight.openflow.protocol.match.Match;
62 import org.projectfloodlight.openflow.protocol.match.MatchField; 69 import org.projectfloodlight.openflow.protocol.match.MatchField;
70 +import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
63 import org.projectfloodlight.openflow.types.ArpOpcode; 71 import org.projectfloodlight.openflow.types.ArpOpcode;
64 import org.projectfloodlight.openflow.types.CircuitSignalID; 72 import org.projectfloodlight.openflow.types.CircuitSignalID;
65 import org.projectfloodlight.openflow.types.EthType; 73 import org.projectfloodlight.openflow.types.EthType;
...@@ -102,6 +110,7 @@ public abstract class FlowModBuilder { ...@@ -102,6 +110,7 @@ public abstract class FlowModBuilder {
102 private final TrafficSelector selector; 110 private final TrafficSelector selector;
103 protected final Long xid; 111 protected final Long xid;
104 protected final Optional<DriverService> driverService; 112 protected final Optional<DriverService> driverService;
113 + protected final DeviceId deviceId;
105 114
106 /** 115 /**
107 * Creates a new flow mod builder. 116 * Creates a new flow mod builder.
...@@ -142,6 +151,7 @@ public abstract class FlowModBuilder { ...@@ -142,6 +151,7 @@ public abstract class FlowModBuilder {
142 this.selector = flowRule.selector(); 151 this.selector = flowRule.selector();
143 this.xid = xid.orElse(0L); 152 this.xid = xid.orElse(0L);
144 this.driverService = driverService; 153 this.driverService = driverService;
154 + this.deviceId = flowRule.deviceId();
145 } 155 }
146 156
147 /** 157 /**
...@@ -446,6 +456,21 @@ public abstract class FlowModBuilder { ...@@ -446,6 +456,21 @@ public abstract class FlowModBuilder {
446 mBuilder.setExact(MatchField.ARP_TPA, 456 mBuilder.setExact(MatchField.ARP_TPA,
447 IPv4Address.of(arpPaCriterion.ip().toInt())); 457 IPv4Address.of(arpPaCriterion.ip().toInt()));
448 break; 458 break;
459 + case EXTENSION:
460 + ExtensionCriterion extensionCriterion = (ExtensionCriterion) c;
461 + OFOxm oxm = buildExtensionOxm(extensionCriterion.extensionSelector());
462 + if (oxm == null) {
463 + log.warn("Unable to build extension selector");
464 + break;
465 + }
466 +
467 + if (oxm.isMasked()) {
468 + mBuilder.setMasked(oxm.getMatchField(), oxm.getValue(), oxm.getMask());
469 + } else {
470 + mBuilder.setExact(oxm.getMatchField(), oxm.getValue());
471 + }
472 +
473 + break;
449 case MPLS_TC: 474 case MPLS_TC:
450 case PBB_ISID: 475 case PBB_ISID:
451 default: 476 default:
...@@ -473,4 +498,21 @@ public abstract class FlowModBuilder { ...@@ -473,4 +498,21 @@ public abstract class FlowModBuilder {
473 return factory; 498 return factory;
474 } 499 }
475 500
501 + private OFOxm buildExtensionOxm(ExtensionSelector extension) {
502 + if (!driverService.isPresent()) {
503 + log.error("No driver service present");
504 + return null;
505 + }
506 + Driver driver = driverService.get().getDriver(deviceId);
507 + if (driver.hasBehaviour(ExtensionSelectorInterpreter.class)) {
508 + DefaultDriverHandler handler =
509 + new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
510 + ExtensionSelectorInterpreter interpreter = handler.behaviour(ExtensionSelectorInterpreter.class);
511 +
512 + return interpreter.mapSelector(factory(), extension);
513 + }
514 +
515 + return null;
516 + }
517 +
476 } 518 }
......
...@@ -18,7 +18,6 @@ package org.onosproject.provider.of.flow.impl; ...@@ -18,7 +18,6 @@ package org.onosproject.provider.of.flow.impl;
18 import com.google.common.collect.Lists; 18 import com.google.common.collect.Lists;
19 import org.onlab.packet.Ip4Address; 19 import org.onlab.packet.Ip4Address;
20 import org.onlab.packet.Ip6Address; 20 import org.onlab.packet.Ip6Address;
21 -import org.onosproject.net.DeviceId;
22 import org.onosproject.net.OchSignal; 21 import org.onosproject.net.OchSignal;
23 import org.onosproject.net.PortNumber; 22 import org.onosproject.net.PortNumber;
24 import org.onosproject.net.driver.DefaultDriverData; 23 import org.onosproject.net.driver.DefaultDriverData;
...@@ -95,7 +94,6 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -95,7 +94,6 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
95 private static final int OFPCML_NO_BUFFER = 0xffff; 94 private static final int OFPCML_NO_BUFFER = 0xffff;
96 95
97 private final TrafficTreatment treatment; 96 private final TrafficTreatment treatment;
98 - private final DeviceId deviceId;
99 97
100 /** 98 /**
101 * Constructor for a flow mod builder for OpenFlow 1.3. 99 * Constructor for a flow mod builder for OpenFlow 1.3.
...@@ -110,7 +108,6 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -110,7 +108,6 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
110 super(flowRule, factory, xid, driverService); 108 super(flowRule, factory, xid, driverService);
111 109
112 this.treatment = flowRule.treatment(); 110 this.treatment = flowRule.treatment();
113 - this.deviceId = flowRule.deviceId();
114 } 111 }
115 112
116 @Override 113 @Override
......