BitOhenry
Committed by Gerrit Code Review

[ONOS-3551] Add implementation of resubmit and resubmit-table to

drivers

Change-Id: Ib96f7f3197968f7e6642cf2368040f340763cef2
...@@ -96,13 +96,17 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou ...@@ -96,13 +96,17 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou
96 IPv4Address.of(tunnelDst.tunnelDst().toInt()))); 96 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
97 } 97 }
98 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { 98 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
99 - // TODO this will be implemented later 99 + NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment;
100 + return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(),
101 + resubmit.table());
100 } 102 }
101 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { 103 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
102 // TODO this will be implemented later 104 // TODO this will be implemented later
103 } 105 }
104 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { 106 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
105 - // TODO this will be implemented later 107 + NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment;
108 + return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(),
109 + resubmitTable.table());
106 } 110 }
107 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { 111 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
108 // TODO this will be implemented later 112 // TODO this will be implemented later
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
17 package org.onosproject.driver.extensions; 17 package org.onosproject.driver.extensions;
18 18
19 import com.google.common.base.MoreObjects; 19 import com.google.common.base.MoreObjects;
20 +import com.google.common.collect.Maps;
21 +
20 import org.onlab.util.KryoNamespace; 22 import org.onlab.util.KryoNamespace;
21 import org.onosproject.net.PortNumber; 23 import org.onosproject.net.PortNumber;
22 import org.onosproject.net.flow.AbstractExtension; 24 import org.onosproject.net.flow.AbstractExtension;
...@@ -24,6 +26,8 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment; ...@@ -24,6 +26,8 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment;
24 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 26 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
25 import org.onosproject.store.serializers.PortNumberSerializer; 27 import org.onosproject.store.serializers.PortNumberSerializer;
26 28
29 +import java.util.HashMap;
30 +import java.util.Map;
27 import java.util.Objects; 31 import java.util.Objects;
28 32
29 import static com.google.common.base.Preconditions.checkNotNull; 33 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -33,10 +37,14 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -33,10 +37,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
33 */ 37 */
34 public class NiciraResubmit extends AbstractExtension implements ExtensionTreatment { 38 public class NiciraResubmit extends AbstractExtension implements ExtensionTreatment {
35 39
40 + private static final short DEFAULT_TABLE_ID = 0;
41 +
36 private PortNumber inPort; 42 private PortNumber inPort;
43 + private short table;
37 44
38 private final KryoNamespace appKryo = new KryoNamespace.Builder() 45 private final KryoNamespace appKryo = new KryoNamespace.Builder()
39 .register(new PortNumberSerializer(), PortNumber.class) 46 .register(new PortNumberSerializer(), PortNumber.class)
47 + .register(Map.class).register(HashMap.class)
40 .register(byte[].class) 48 .register(byte[].class)
41 .build(); 49 .build();
42 50
...@@ -45,6 +53,7 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm ...@@ -45,6 +53,7 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm
45 */ 53 */
46 NiciraResubmit() { 54 NiciraResubmit() {
47 inPort = null; 55 inPort = null;
56 + table = DEFAULT_TABLE_ID;
48 } 57 }
49 58
50 /** 59 /**
...@@ -55,6 +64,7 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm ...@@ -55,6 +64,7 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm
55 public NiciraResubmit(PortNumber inPort) { 64 public NiciraResubmit(PortNumber inPort) {
56 checkNotNull(inPort); 65 checkNotNull(inPort);
57 this.inPort = inPort; 66 this.inPort = inPort;
67 + this.table = DEFAULT_TABLE_ID;
58 } 68 }
59 69
60 /** 70 /**
...@@ -66,6 +76,15 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm ...@@ -66,6 +76,15 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm
66 return inPort; 76 return inPort;
67 } 77 }
68 78
79 + /**
80 + * Gets the table.
81 + *
82 + * @return table
83 + */
84 + public short table() {
85 + return table;
86 + }
87 +
69 @Override 88 @Override
70 public ExtensionTreatmentType type() { 89 public ExtensionTreatmentType type() {
71 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type(); 90 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type();
...@@ -73,17 +92,22 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm ...@@ -73,17 +92,22 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm
73 92
74 @Override 93 @Override
75 public void deserialize(byte[] data) { 94 public void deserialize(byte[] data) {
76 - inPort = appKryo.deserialize(data); 95 + Map<String, Object> values = appKryo.deserialize(data);
96 + inPort = (PortNumber) values.get("inPort");
97 + table = (short) values.get("table");
77 } 98 }
78 99
79 @Override 100 @Override
80 public byte[] serialize() { 101 public byte[] serialize() {
81 - return appKryo.serialize(inPort); 102 + Map<String, Object> values = Maps.newHashMap();
103 + values.put("inPort", inPort);
104 + values.put("table", table);
105 + return appKryo.serialize(values);
82 } 106 }
83 107
84 @Override 108 @Override
85 public int hashCode() { 109 public int hashCode() {
86 - return Objects.hash(inPort); 110 + return Objects.hash(inPort, table);
87 } 111 }
88 112
89 @Override 113 @Override
...@@ -93,8 +117,8 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm ...@@ -93,8 +117,8 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm
93 } 117 }
94 if (obj instanceof NiciraResubmit) { 118 if (obj instanceof NiciraResubmit) {
95 NiciraResubmit that = (NiciraResubmit) obj; 119 NiciraResubmit that = (NiciraResubmit) obj;
96 - return Objects.equals(inPort, that.inPort); 120 + return Objects.equals(inPort, that.inPort)
97 - 121 + && (table == that.table());
98 } 122 }
99 return false; 123 return false;
100 } 124 }
...@@ -103,6 +127,7 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm ...@@ -103,6 +127,7 @@ public class NiciraResubmit extends AbstractExtension implements ExtensionTreatm
103 public String toString() { 127 public String toString() {
104 return MoreObjects.toStringHelper(getClass()) 128 return MoreObjects.toStringHelper(getClass())
105 .add("inPort", inPort) 129 .add("inPort", inPort)
130 + .add("table", table)
106 .toString(); 131 .toString();
107 } 132 }
108 } 133 }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 package org.onosproject.driver.extensions; 17 package org.onosproject.driver.extensions;
18 18
19 import com.google.common.base.MoreObjects; 19 import com.google.common.base.MoreObjects;
20 +import com.google.common.collect.Maps;
20 21
21 import org.onlab.util.KryoNamespace; 22 import org.onlab.util.KryoNamespace;
22 import org.onosproject.net.PortNumber; 23 import org.onosproject.net.PortNumber;
...@@ -25,8 +26,8 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment; ...@@ -25,8 +26,8 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment;
25 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 26 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26 import org.onosproject.store.serializers.PortNumberSerializer; 27 import org.onosproject.store.serializers.PortNumberSerializer;
27 28
28 -import java.util.ArrayList; 29 +import java.util.HashMap;
29 -import java.util.List; 30 +import java.util.Map;
30 import java.util.Objects; 31 import java.util.Objects;
31 32
32 import static com.google.common.base.Preconditions.checkNotNull; 33 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -37,13 +38,14 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -37,13 +38,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
37 public class NiciraResubmitTable extends AbstractExtension implements 38 public class NiciraResubmitTable extends AbstractExtension implements
38 ExtensionTreatment { 39 ExtensionTreatment {
39 40
40 - //the list of the in port number(PortNumber) and the table(short) 41 + private static final PortNumber DEFAULT_IN_PORT = PortNumber.portNumber(65528);
41 - private List<Object> inPortAndTable = new ArrayList<Object>(); 42 +
43 + private PortNumber inPort;
44 + private short table;
42 45
43 private final KryoNamespace appKryo = new KryoNamespace.Builder() 46 private final KryoNamespace appKryo = new KryoNamespace.Builder()
44 - .register(ArrayList.class)
45 .register(new PortNumberSerializer(), PortNumber.class) 47 .register(new PortNumberSerializer(), PortNumber.class)
46 - .register(short.class) 48 + .register(Map.class).register(HashMap.class)
47 .register(byte[].class) 49 .register(byte[].class)
48 .build(); 50 .build();
49 51
...@@ -51,26 +53,50 @@ public class NiciraResubmitTable extends AbstractExtension implements ...@@ -51,26 +53,50 @@ public class NiciraResubmitTable extends AbstractExtension implements
51 * Creates a new resubmit-table instruction. 53 * Creates a new resubmit-table instruction.
52 */ 54 */
53 NiciraResubmitTable() { 55 NiciraResubmitTable() {
54 - inPortAndTable = null; 56 + inPort = DEFAULT_IN_PORT;
57 + table = -1;
55 } 58 }
56 59
57 /** 60 /**
58 * Creates a new resubmit-table instruction with a particular inPort and table. 61 * Creates a new resubmit-table instruction with a particular inPort and table.
59 * 62 *
60 - * @param inPortAndTable the list of in port number and table 63 + * @param inPort the in port number
64 + * @param table table
65 + */
66 + public NiciraResubmitTable(PortNumber inPort, short table) {
67 + checkNotNull(inPort);
68 + checkNotNull(table);
69 + this.inPort = inPort;
70 + this.table = table;
71 + }
72 +
73 + /**
74 + * Creates a new resubmit-table instruction with a particular table.
75 + *
76 + * @param table table
61 */ 77 */
62 - public NiciraResubmitTable(List<Object> inPortAndTable) { 78 + public NiciraResubmitTable(short table) {
63 - checkNotNull(inPortAndTable); 79 + checkNotNull(table);
64 - this.inPortAndTable = inPortAndTable; 80 + this.inPort = DEFAULT_IN_PORT;
81 + this.table = table;
65 } 82 }
66 83
67 /** 84 /**
68 - * Gets the inPortAndTable. 85 + * Gets the inPort.
69 * 86 *
70 - * @return inPortAndTable 87 + * @return inPort
71 */ 88 */
72 - public List<Object> inPortAndTable() { 89 + public PortNumber inPort() {
73 - return inPortAndTable; 90 + return inPort;
91 + }
92 +
93 + /**
94 + * Gets the table.
95 + *
96 + * @return table
97 + */
98 + public short table() {
99 + return table;
74 } 100 }
75 101
76 @Override 102 @Override
...@@ -80,17 +106,22 @@ public class NiciraResubmitTable extends AbstractExtension implements ...@@ -80,17 +106,22 @@ public class NiciraResubmitTable extends AbstractExtension implements
80 106
81 @Override 107 @Override
82 public void deserialize(byte[] data) { 108 public void deserialize(byte[] data) {
83 - inPortAndTable = appKryo.deserialize(data); 109 + Map<String, Object> values = appKryo.deserialize(data);
110 + inPort = (PortNumber) values.get("inPort");
111 + table = (short) values.get("table");
84 } 112 }
85 113
86 @Override 114 @Override
87 public byte[] serialize() { 115 public byte[] serialize() {
88 - return appKryo.serialize(inPortAndTable); 116 + Map<String, Object> values = Maps.newHashMap();
117 + values.put("inPort", inPort);
118 + values.put("table", table);
119 + return appKryo.serialize(values);
89 } 120 }
90 121
91 @Override 122 @Override
92 public int hashCode() { 123 public int hashCode() {
93 - return Objects.hash(inPortAndTable); 124 + return Objects.hash(inPort, table);
94 } 125 }
95 126
96 @Override 127 @Override
...@@ -100,8 +131,8 @@ public class NiciraResubmitTable extends AbstractExtension implements ...@@ -100,8 +131,8 @@ public class NiciraResubmitTable extends AbstractExtension implements
100 } 131 }
101 if (obj instanceof NiciraResubmitTable) { 132 if (obj instanceof NiciraResubmitTable) {
102 NiciraResubmitTable that = (NiciraResubmitTable) obj; 133 NiciraResubmitTable that = (NiciraResubmitTable) obj;
103 - return Objects.equals(inPortAndTable, that.inPortAndTable); 134 + return Objects.equals(inPort, that.inPort)
104 - 135 + && (table == that.table);
105 } 136 }
106 return false; 137 return false;
107 } 138 }
...@@ -109,6 +140,8 @@ public class NiciraResubmitTable extends AbstractExtension implements ...@@ -109,6 +140,8 @@ public class NiciraResubmitTable extends AbstractExtension implements
109 @Override 140 @Override
110 public String toString() { 141 public String toString() {
111 return MoreObjects.toStringHelper(getClass()) 142 return MoreObjects.toStringHelper(getClass())
112 - .add("inPortAndTable", inPortAndTable).toString(); 143 + .add("inPort", inPort)
144 + .add("table", table)
145 + .toString();
113 } 146 }
114 } 147 }
...\ No newline at end of file ...\ No newline at end of file
......