samueljcc
Committed by Gerrit Code Review

[ONOS-2860] ONOSFW L3 uses ARP table as arp proxy. It need modify ARP

request packet to response packet. OpenFlow protocol provides some
extension action to support it. e.g. move and load. But for now OpenFlow
java implementation doesn't support for them.

Change-Id: I30506f9230bb7ec75952893fdb07d15a866b877d
...@@ -40,7 +40,11 @@ public final class ExtensionTreatmentType { ...@@ -40,7 +40,11 @@ public final class ExtensionTreatmentType {
40 NICIRA_SET_NSH_CH1(34), 40 NICIRA_SET_NSH_CH1(34),
41 NICIRA_SET_NSH_CH2(35), 41 NICIRA_SET_NSH_CH2(35),
42 NICIRA_SET_NSH_CH3(36), 42 NICIRA_SET_NSH_CH3(36),
43 - NICIRA_SET_NSH_CH4(37); 43 + NICIRA_SET_NSH_CH4(37),
44 + NICIRA_MOV_ARP_SHA_TO_THA(2),
45 + NICIRA_MOV_ARP_SPA_TO_TPA(3),
46 + NICIRA_MOV_ETH_SRC_TO_DST(4),
47 + NICIRA_MOV_IP_SRC_TO_DST(5);
44 48
45 private ExtensionTreatmentType type; 49 private ExtensionTreatmentType type;
46 50
......
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 +package org.onosproject.driver.extensions;
17 +
18 +import java.util.Map;
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.collect.Maps;
27 +
28 +/**
29 + * Default implementation of Move treatment.
30 + */
31 +public class DefaultMoveExtensionTreatment extends AbstractExtension
32 + implements MoveExtensionTreatment {
33 +
34 + private int srcOfs;
35 + private int dstOfs;
36 + private int nBits;
37 + private int src;
38 + private int dst;
39 + private ExtensionTreatmentType type;
40 +
41 + private final KryoNamespace appKryo = new KryoNamespace.Builder()
42 + .register(byte[].class).register(Integer.class).register(Map.class)
43 + .build();
44 +
45 + /**
46 + * Creates a new move Treatment.
47 + *
48 + * @param srcOfs source offset
49 + * @param dstOfs destination offset
50 + * @param nBits nbits
51 + * @param src source
52 + * @param dst destination
53 + */
54 + public DefaultMoveExtensionTreatment(int srcOfs, int dstOfs, int nBits,
55 + int src, int dst, ExtensionTreatmentType type) {
56 + this.srcOfs = srcOfs;
57 + this.dstOfs = dstOfs;
58 + this.nBits = nBits;
59 + this.src = src;
60 + this.dst = dst;
61 + this.type = type;
62 + }
63 +
64 + @Override
65 + public ExtensionTreatmentType type() {
66 + return type;
67 + }
68 +
69 + @Override
70 + public byte[] serialize() {
71 + Map<String, Integer> values = Maps.newHashMap();
72 + values.put("srcOfs", srcOfs);
73 + values.put("dstOfs", dstOfs);
74 + values.put("nBits", nBits);
75 + values.put("src", src);
76 + values.put("dst", dst);
77 + values.put("type", ExtensionTreatmentType.ExtensionTreatmentTypes.valueOf(type.toString()).ordinal());
78 + return appKryo.serialize(values);
79 + }
80 +
81 + @Override
82 + public void deserialize(byte[] data) {
83 + Map<String, Integer> values = appKryo.deserialize(data);
84 + srcOfs = values.get("srcOfs");
85 + dstOfs = values.get("dstOfs");
86 + nBits = values.get("nBits");
87 + src = values.get("src");
88 + dst = values.get("dst");
89 + type = new ExtensionTreatmentType(values.get("type").intValue());
90 + }
91 +
92 + @Override
93 + public int srcOffset() {
94 + return srcOfs;
95 + }
96 +
97 + @Override
98 + public int dstOffset() {
99 + return dstOfs;
100 + }
101 +
102 + @Override
103 + public int src() {
104 + return src;
105 + }
106 +
107 + @Override
108 + public int dst() {
109 + return dst;
110 + }
111 +
112 + @Override
113 + public int nBits() {
114 + return nBits;
115 + }
116 +
117 + @Override
118 + public int hashCode() {
119 + return Objects.hash(srcOfs, dstOfs, src, dst, nBits);
120 + }
121 +
122 + @Override
123 + public boolean equals(Object obj) {
124 + if (this == obj) {
125 + return true;
126 + }
127 + if (obj instanceof DefaultMoveExtensionTreatment) {
128 + DefaultMoveExtensionTreatment that = (DefaultMoveExtensionTreatment) obj;
129 + return Objects.equals(srcOfs, that.srcOfs)
130 + && Objects.equals(dstOfs, that.dstOfs)
131 + && Objects.equals(src, that.src)
132 + && Objects.equals(dst, that.dst)
133 + && Objects.equals(nBits, that.nBits);
134 +
135 + }
136 + return false;
137 + }
138 +
139 + @Override
140 + public String toString() {
141 + return MoreObjects.toStringHelper(getClass()).add("srcOfs", srcOfs)
142 + .add("dstOfs", dstOfs).add("nBits", nBits).add("src", src)
143 + .add("dst", dst).toString();
144 + }
145 +}
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 +package org.onosproject.driver.extensions;
17 +
18 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
19 +
20 +/**
21 + * The abstraction of Move Treatment.
22 + */
23 +public interface MoveExtensionTreatment extends ExtensionTreatment {
24 +
25 + /**
26 + * Returns SRC_OFS field of move extension action.
27 + *
28 + * @return SRC_OFS
29 + */
30 + int srcOffset();
31 +
32 + /**
33 + * Returns DST_OFS field of move extension action.
34 + *
35 + * @return DST_OFS
36 + */
37 + int dstOffset();
38 +
39 + /**
40 + * Returns SRC field of move extension action.
41 + *
42 + * @return SRC
43 + */
44 + int src();
45 +
46 + /**
47 + * Returns DST field of move extension action.
48 + *
49 + * @return DST
50 + */
51 + int dst();
52 +
53 + /**
54 + * Returns N_BITS field of move extension action.
55 + *
56 + * @return N_BITS
57 + */
58 + int nBits();
59 +}
...@@ -68,6 +68,22 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou ...@@ -68,6 +68,22 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou
68 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { 68 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
69 return true; 69 return true;
70 } 70 }
71 + if (extensionTreatmentType.equals(
72 + ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
73 + return true;
74 + }
75 + if (extensionTreatmentType.equals(
76 + ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
77 + return true;
78 + }
79 + if (extensionTreatmentType.equals(
80 + ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
81 + return true;
82 + }
83 + if (extensionTreatmentType.equals(
84 + ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
85 + return true;
86 + }
71 return false; 87 return false;
72 } 88 }
73 89
...@@ -103,6 +119,12 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou ...@@ -103,6 +119,12 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou
103 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { 119 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
104 // TODO this will be implemented later 120 // TODO this will be implemented later
105 } 121 }
122 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
123 + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())
124 + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())
125 + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
126 + // TODO this will be implemented later
127 + }
106 return null; 128 return null;
107 } 129 }
108 130
...@@ -146,6 +168,18 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou ...@@ -146,6 +168,18 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou
146 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { 168 || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
147 return new NiciraSetNshContextHeader(type); 169 return new NiciraSetNshContextHeader(type);
148 } 170 }
171 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type())) {
172 + return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha();
173 + }
174 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type())) {
175 + return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa();
176 + }
177 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type())) {
178 + return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst();
179 + }
180 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) {
181 + return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst();
182 + }
149 throw new UnsupportedOperationException( 183 throw new UnsupportedOperationException(
150 "Driver does not support extension type " + type.toString()); 184 "Driver does not support extension type " + type.toString());
151 } 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 +package org.onosproject.driver.extensions;
17 +
18 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
19 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
20 +
21 +/**
22 + * The factory of move treatment.
23 + */
24 +public final class NiciraMoveTreatmentFactory {
25 +
26 + /**
27 + * Public constructor is prohibited.
28 + */
29 + private NiciraMoveTreatmentFactory() {
30 +
31 + }
32 +
33 + /**
34 + * Creates a move treatment that move arp sha to tha.
35 + *
36 + * @return ExtensionTreatment
37 + */
38 + public static ExtensionTreatment createNiciraMovArpShaToTha() {
39 + int srcOfs = 0;
40 + int dstOfs = 0;
41 + int nBits = 48;
42 + int srcSha = 0x00012206;
43 + int dstTha = 0x00012406;
44 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcSha,
45 + dstTha,
46 + ExtensionTreatmentType.ExtensionTreatmentTypes
47 + .NICIRA_MOV_ARP_SHA_TO_THA.type());
48 + }
49 +
50 + /**
51 + * Creates a move treatment that move arp spa to tpa.
52 + *
53 + * @return ExtensionTreatment
54 + */
55 + public static ExtensionTreatment createNiciraMovArpSpaToTpa() {
56 + int srcOfs = 0;
57 + int dstOfs = 0;
58 + int nBits = 32;
59 + int srcSpa = 0x00002004;
60 + int dstTpa = 0x00002204;
61 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcSpa,
62 + dstTpa,
63 + ExtensionTreatmentType.ExtensionTreatmentTypes
64 + .NICIRA_MOV_ARP_SPA_TO_TPA.type());
65 + }
66 +
67 + /**
68 + * Creates a move treatment that move eth src to dst.
69 + *
70 + * @return ExtensionTreatment
71 + */
72 + public static ExtensionTreatment createNiciraMovEthSrcToDst() {
73 + int srcOfs = 0;
74 + int dstOfs = 0;
75 + int nBits = 48;
76 + int srcEth = 0x00000406;
77 + int dstEth = 0x00000206;
78 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcEth,
79 + dstEth,
80 + ExtensionTreatmentType.ExtensionTreatmentTypes
81 + .NICIRA_MOV_ETH_SRC_TO_DST.type());
82 + }
83 +
84 + /**
85 + * Creates a move treatment that move ip src to dst.
86 + *
87 + * @return ExtensionTreatment
88 + */
89 + public static ExtensionTreatment createNiciraMovIpSrcToDst() {
90 + int srcOfs = 0;
91 + int dstOfs = 0;
92 + int nBits = 32;
93 + int srcIp = 0x00000e04;
94 + int dstIp = 0x00001006;
95 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcIp,
96 + dstIp,
97 + ExtensionTreatmentType.ExtensionTreatmentTypes
98 + .NICIRA_MOV_IP_SRC_TO_DST.type());
99 + }
100 +}