Rusty Eddy
Committed by Gerrit Code Review

Added McastConnectPoint to track membership source

for egress ConnectPoints by STATIC config, PIM and
IGMP.

Change-Id: Ia913ee697e0cae32dd74db508e5ea2cba0d47c45
...@@ -20,6 +20,7 @@ import org.apache.karaf.shell.commands.Command; ...@@ -20,6 +20,7 @@ import org.apache.karaf.shell.commands.Command;
20 import org.onlab.packet.IpPrefix; 20 import org.onlab.packet.IpPrefix;
21 import org.onosproject.cli.AbstractShellCommand; 21 import org.onosproject.cli.AbstractShellCommand;
22 22
23 +import org.onosproject.mfwd.impl.McastConnectPoint;
23 import org.onosproject.mfwd.impl.McastRouteBase; 24 import org.onosproject.mfwd.impl.McastRouteBase;
24 import org.onosproject.mfwd.impl.McastRouteTable; 25 import org.onosproject.mfwd.impl.McastRouteTable;
25 26
...@@ -76,21 +77,13 @@ public class McastJoinCommand extends AbstractShellCommand { ...@@ -76,21 +77,13 @@ public class McastJoinCommand extends AbstractShellCommand {
76 if (ingressPort != null) { 77 if (ingressPort != null) {
77 String inCP = ingressPort; 78 String inCP = ingressPort;
78 log.debug("Ingress port provided: " + inCP); 79 log.debug("Ingress port provided: " + inCP);
79 - String [] cp = inCP.split("/"); 80 + mr.addIngressPoint(inCP);
80 - mr.addIngressPoint(cp[0], Long.parseLong(cp[1]));
81 - } else {
82 - return;
83 - }
84 -
85 - if (ports == null) {
86 - return;
87 } 81 }
88 82
89 for (int i = 0; i < ports.length; i++) { 83 for (int i = 0; i < ports.length; i++) {
90 String egCP = ports[i]; 84 String egCP = ports[i];
91 log.debug("Egress port provided: " + egCP); 85 log.debug("Egress port provided: " + egCP);
92 - String [] cp = egCP.split("/"); 86 + mr.addEgressPoint(egCP, McastConnectPoint.JoinSource.STATIC);
93 - mr.addEgressPoint(cp[0], Long.parseLong(cp[1]));
94 } 87 }
95 print("Added the mcast route"); 88 print("Added the mcast route");
96 } 89 }
......
...@@ -72,7 +72,7 @@ public class McastShowCommand extends AbstractShellCommand { ...@@ -72,7 +72,7 @@ public class McastShowCommand extends AbstractShellCommand {
72 inPort = mg.getIngressPoint().toString(); 72 inPort = mg.getIngressPoint().toString();
73 log.info("Multicast Ingress: " + inPort); 73 log.info("Multicast Ingress: " + inPort);
74 } 74 }
75 - Set<ConnectPoint> eps = mg.getEgressPoints(); 75 + Set<ConnectPoint> eps = mg.getEgressConnectPoints();
76 if (eps != null && !eps.isEmpty()) { 76 if (eps != null && !eps.isEmpty()) {
77 outPorts = eps.toString(); 77 outPorts = eps.toString();
78 } 78 }
......
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.mfwd.impl;
17 +
18 +import org.onosproject.net.ConnectPoint;
19 +import java.util.EnumSet;
20 +import java.util.Set;
21 +
22 +/**
23 + * Mulitcast ConnectPoint adds a variable to track the usage
24 + * of these multicast endpoints.
25 + */
26 +public class McastConnectPoint {
27 +
28 + private ConnectPoint connectPoint;
29 +
30 + public enum JoinSource {
31 + STATIC, IGMP, PIM;
32 + }
33 +
34 + public EnumSet<JoinSource> interest = EnumSet.noneOf(JoinSource.class);
35 +
36 + public McastConnectPoint(ConnectPoint cp) {
37 + this.connectPoint = cp;
38 + }
39 +
40 + public McastConnectPoint(ConnectPoint cp, JoinSource src) {
41 + this.connectPoint = cp;
42 + interest.add(src);
43 + }
44 +
45 + public McastConnectPoint(String connectPoint, JoinSource src) {
46 + ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPoint);
47 + this.connectPoint = cp;
48 + this.interest.add(src);
49 + }
50 +
51 + /**
52 + * Get the connect point.
53 + *
54 + * @return connectPoint
55 + */
56 + public ConnectPoint getConnectPoint() {
57 + return connectPoint;
58 + }
59 +
60 + /**
61 + * Get the sources of interest for this egressPoint.
62 + *
63 + * @return interest flags
64 + */
65 + public Set<JoinSource> getInterest() {
66 + return interest;
67 + }
68 +}
...@@ -222,7 +222,7 @@ public class McastForwarding { ...@@ -222,7 +222,7 @@ public class McastForwarding {
222 private void forwardPacketToDst(PacketContext context, McastRoute entry) { 222 private void forwardPacketToDst(PacketContext context, McastRoute entry) {
223 223
224 // Send the pack out each of the respective egress ports 224 // Send the pack out each of the respective egress ports
225 - for (ConnectPoint egress : entry.getEgressPoints()) { 225 + for (ConnectPoint egress : entry.getEgressConnectPoints()) {
226 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 226 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
227 .setOutput(egress.port()).build(); 227 .setOutput(egress.port()).build();
228 228
......
...@@ -101,8 +101,8 @@ public class McastIntentManager { ...@@ -101,8 +101,8 @@ public class McastIntentManager {
101 .appId(McastForwarding.getAppId()) 101 .appId(McastForwarding.getAppId())
102 .selector(selector.build()) 102 .selector(selector.build())
103 .treatment(treatment) 103 .treatment(treatment)
104 - .ingressPoint(mroute.getIngressPoint()) 104 + .ingressPoint(mroute.getIngressPoint().getConnectPoint())
105 - .egressPoints(mroute.getEgressPoints()). 105 + .egressPoints(mroute.getEgressConnectPoints()).
106 build(); 106 build();
107 107
108 intentService.submit(intent); 108 intentService.submit(intent);
......
...@@ -57,48 +57,91 @@ interface McastRoute { ...@@ -57,48 +57,91 @@ interface McastRoute {
57 public boolean isIp6(); 57 public boolean isIp6();
58 58
59 /** 59 /**
60 - * Add the ingress ConnectPoint with a ConnectPoint. 60 + * Add the ingress ConnectPoint.
61 * 61 *
62 - * @param ingress ingress point 62 + * @param cpstr string representing a ConnectPoint
63 + * @return whether ingress has been added, only add if ingressPoint is null
63 */ 64 */
64 - public void addIngressPoint(ConnectPoint ingress); 65 + public boolean addIngressPoint(String cpstr);
65 66
66 /** 67 /**
67 - * Add the ingress Connect Point using. .. 68 + * Add the ingress ConnectPoint.
68 * 69 *
69 - * @param deviceId device ID 70 + * @param cp the ConnectPoint of incoming traffic.
70 - * @param portNum port number 71 + * @return whether ingress has been added, only add if ingressPoint is null
71 */ 72 */
72 - public void addIngressPoint(String deviceId, long portNum); 73 + public boolean addIngressPoint(ConnectPoint cp);
73 74
74 /** 75 /**
75 * Get the ingress connect point. 76 * Get the ingress connect point.
76 * 77 *
77 * @return the ingress connect point 78 * @return the ingress connect point
78 */ 79 */
79 - public ConnectPoint getIngressPoint(); 80 + public McastConnectPoint getIngressPoint();
80 81
81 /** 82 /**
82 * Add an egress connect point. 83 * Add an egress connect point.
83 * 84 *
84 - * @param member the egress ConnectPoint to be added 85 + * @param cp the egress McastConnectPoint to be added
86 + * @return return the McastConnectPoint
85 */ 87 */
86 - public void addEgressPoint(ConnectPoint member); 88 + public McastConnectPoint addEgressPoint(ConnectPoint cp);
87 89
88 /** 90 /**
89 * Add an egress connect point. 91 * Add an egress connect point.
90 * 92 *
91 - * @param deviceId the device ID of the connect point 93 + * @param connectPoint deviceId/portNum
92 - * @param portNum the port number of the connect point 94 + * @return return the McastConnectPoint
93 */ 95 */
94 - public void addEgressPoint(String deviceId, long portNum); 96 + public McastConnectPoint addEgressPoint(String connectPoint);
97 +
98 + /**
99 + * Add an egress connect point.
100 + *
101 + * @param cp the egress McastConnectPoint to be added
102 + * @param interest the protocol that has shown interest in this route
103 + * @return return the McastConnectPoint
104 + */
105 + public McastConnectPoint addEgressPoint(ConnectPoint cp, McastConnectPoint.JoinSource interest);
106 +
107 + /**
108 + * Add an egress connect point.
109 + *
110 + * @param connectPoint deviceId/portNum
111 + * @param interest the protocol that has shown interest in this route
112 + * @return return the McastConnectPoint
113 + */
114 + public McastConnectPoint addEgressPoint(String connectPoint, McastConnectPoint.JoinSource interest);
115 +
116 + /**
117 + * Get the egress connect points.
118 + *
119 + * @return a set of egress connect points
120 + */
121 + public Set<McastConnectPoint> getEgressPoints();
95 122
96 /** 123 /**
97 * Get the egress connect points. 124 * Get the egress connect points.
98 * 125 *
99 * @return a set of egress connect points 126 * @return a set of egress connect points
100 */ 127 */
101 - public Set<ConnectPoint> getEgressPoints(); 128 + public Set<ConnectPoint> getEgressConnectPoints();
129 +
130 + /**
131 + * Find the egress connect point if it exists.
132 + *
133 + * @return the connect point when found, null otherwise.
134 + */
135 + public McastConnectPoint findEgressConnectPoint(ConnectPoint cp);
136 +
137 + /**
138 + * remove Interest from a McastConnectPoint.
139 + *
140 + * @param mcp connect point.
141 + * @param interest the protocol interested in this multicast stream
142 + * @return whether or not interest was removed
143 + */
144 + public boolean removeInterest(McastConnectPoint mcp, McastConnectPoint.JoinSource interest);
102 145
103 /** 146 /**
104 * Increment the punt count. 147 * Increment the punt count.
......
...@@ -17,10 +17,9 @@ package org.onosproject.mfwd.impl; ...@@ -17,10 +17,9 @@ package org.onosproject.mfwd.impl;
17 17
18 import static com.google.common.base.Preconditions.checkNotNull; 18 import static com.google.common.base.Preconditions.checkNotNull;
19 19
20 +import org.apache.commons.collections.set.ListOrderedSet;
20 import org.onlab.packet.IpPrefix; 21 import org.onlab.packet.IpPrefix;
21 import org.onosproject.net.ConnectPoint; 22 import org.onosproject.net.ConnectPoint;
22 -import org.onosproject.net.DeviceId;
23 -import org.onosproject.net.PortNumber;
24 import org.onosproject.net.intent.SinglePointToMultiPointIntent; 23 import org.onosproject.net.intent.SinglePointToMultiPointIntent;
25 import org.onosproject.net.intent.Key; 24 import org.onosproject.net.intent.Key;
26 25
...@@ -34,11 +33,13 @@ public class McastRouteBase implements McastRoute { ...@@ -34,11 +33,13 @@ public class McastRouteBase implements McastRoute {
34 protected final IpPrefix gaddr; 33 protected final IpPrefix gaddr;
35 protected final IpPrefix saddr; 34 protected final IpPrefix saddr;
36 35
37 - protected ConnectPoint ingressPoint; 36 + protected McastConnectPoint ingressPoint;
38 - protected Set<ConnectPoint> egressPoints; 37 + protected Set<McastConnectPoint> egressPoints;
39 38
40 protected boolean isGroup = false; 39 protected boolean isGroup = false;
41 40
41 + protected boolean dirty = false;
42 +
42 /** 43 /**
43 * How may times has this packet been punted. 44 * How may times has this packet been punted.
44 */ 45 */
...@@ -160,58 +161,120 @@ public class McastRouteBase implements McastRoute { ...@@ -160,58 +161,120 @@ public class McastRouteBase implements McastRoute {
160 } 161 }
161 162
162 /** 163 /**
164 + * Get the dirty state.
165 + *
166 + * @return whether this route is dirty or not.
167 + */
168 + public boolean getDirty() {
169 + return this.dirty;
170 + }
171 +
172 + /**
173 + * Set the dirty state to indicate that something changed.
174 + * This may require an update to the flow tables (intents).
175 + *
176 + * @param dirty set the dirty bit
177 + */
178 + public void setDirty(boolean dirty) {
179 + this.dirty = dirty;
180 + }
181 +
182 + /**
163 * Add an ingress point to this route. 183 * Add an ingress point to this route.
164 * 184 *
165 * @param ingress incoming connect point 185 * @param ingress incoming connect point
186 + * @return whether ingress has been added, only add if ingressPoint is null
166 */ 187 */
167 - @Override 188 + public boolean addIngressPoint(ConnectPoint ingress) {
168 - public void addIngressPoint(ConnectPoint ingress) { 189 +
169 - ingressPoint = checkNotNull(ingress); 190 + // Do NOT add the ingressPoint if it is not null.
191 + if (this.ingressPoint != null) {
192 + // TODO: Log an warning.
193 + return false;
194 + }
195 + this.ingressPoint = new McastConnectPoint(checkNotNull(ingress));
196 + setDirty(true);
197 + return true;
170 } 198 }
171 199
172 /** 200 /**
173 * Add or modify the ingress connect point. 201 * Add or modify the ingress connect point.
174 * 202 *
175 - * @param deviceId the switch device Id 203 + * @param connectPoint string switch device Id
176 - * @param portNum the ingress port number 204 + * @return whether ingress has been added, only add if ingressPoint is null
177 */ 205 */
178 - @Override 206 + public boolean addIngressPoint(String connectPoint) {
179 - public void addIngressPoint(String deviceId, long portNum) { 207 +
180 - ingressPoint = new ConnectPoint( 208 + if (this.ingressPoint != null) {
181 - DeviceId.deviceId(deviceId), 209 + // TODO: log a warning.
182 - PortNumber.portNumber(portNum)); 210 + return false;
211 + }
212 + ConnectPoint cp = ConnectPoint.deviceConnectPoint(checkNotNull(connectPoint));
213 + return this.addIngressPoint(cp);
183 } 214 }
184 215
185 /** 216 /**
186 - * Get the ingress ConnectPoint. 217 + * Get the ingress McastConnectPoint.
187 * 218 *
188 - * @return the ingress ConnectPoint 219 + * @return the ingress McastConnectPoint
189 */ 220 */
190 - @Override 221 + public McastConnectPoint getIngressPoint() {
191 - public ConnectPoint getIngressPoint() {
192 return this.ingressPoint; 222 return this.ingressPoint;
193 } 223 }
194 224
195 /** 225 /**
196 - * Add an egress ConnectPoint. 226 + * Add an egress McastConnectPoint.
197 * 227 *
198 - * @param member member egress connect point 228 + * @param cp egress connect point
229 + * @return return the McastConnectPoint
199 */ 230 */
200 - @Override 231 + public McastConnectPoint addEgressPoint(ConnectPoint cp) {
201 - public void addEgressPoint(ConnectPoint member) { 232 + McastConnectPoint mcp = this.findEgressConnectPoint(cp);
202 - egressPoints.add(checkNotNull(member)); 233 + if (mcp == null) {
234 + mcp = new McastConnectPoint(checkNotNull(cp));
235 + egressPoints.add(mcp);
236 + setDirty(true);
237 + }
238 + return mcp;
203 } 239 }
204 240
205 /** 241 /**
206 - * Add an egress ConnectPoint. 242 + * Add an egress connect point from a string.
207 * 243 *
208 - * @param deviceId deviceId of the connect point 244 + * @param connectPoint string representing a connect point
209 - * @param portNum portNum of the connect point 245 + * @return the MulticastConnectPoint
210 */ 246 */
211 - @Override 247 + public McastConnectPoint addEgressPoint(String connectPoint) {
212 - public void addEgressPoint(String deviceId, long portNum) { 248 + checkNotNull(connectPoint);
213 - ConnectPoint cp = new ConnectPoint(DeviceId.deviceId(deviceId), PortNumber.portNumber(portNum)); 249 + return this.addEgressPoint(ConnectPoint.deviceConnectPoint(connectPoint));
214 - this.egressPoints.add(cp); 250 + }
251 +
252 + /**
253 + * Add an egress McastConnectPoint.
254 + *
255 + * @param cp the egress connect point
256 + * @param interest the source of interest for mcast traffic
257 + */
258 + public McastConnectPoint addEgressPoint(ConnectPoint cp, McastConnectPoint.JoinSource interest) {
259 + checkNotNull(cp);
260 + checkNotNull(interest);
261 + McastConnectPoint mcp = this.addEgressPoint(cp);
262 + if (mcp != null) {
263 + mcp.interest.add(interest);
264 + setDirty(true);
265 + }
266 + return mcp;
267 + }
268 +
269 + /**
270 + * Add an egress McastConnectPoint.
271 + *
272 + * @param cpstr deviceId/port of the connect point
273 + */
274 + public McastConnectPoint addEgressPoint(String cpstr, McastConnectPoint.JoinSource interest) {
275 + checkNotNull(cpstr);
276 + checkNotNull(interest);
277 + return this.addEgressPoint(ConnectPoint.deviceConnectPoint(cpstr), interest);
215 } 278 }
216 279
217 /** 280 /**
...@@ -219,12 +282,57 @@ public class McastRouteBase implements McastRoute { ...@@ -219,12 +282,57 @@ public class McastRouteBase implements McastRoute {
219 * 282 *
220 * @return Set of egress connect points 283 * @return Set of egress connect points
221 */ 284 */
222 - @Override 285 + public Set<McastConnectPoint> getEgressPoints() {
223 - public Set<ConnectPoint> getEgressPoints() {
224 return egressPoints; 286 return egressPoints;
225 } 287 }
226 288
227 /** 289 /**
290 + * Get egress McastConnectPoints points as ConnectPoints for intent system.
291 + *
292 + * @return Set of egress ConnectPoints
293 + */
294 + public Set<ConnectPoint> getEgressConnectPoints() {
295 + Set<ConnectPoint> cps = new ListOrderedSet();
296 +
297 + for (McastConnectPoint mcp : egressPoints) {
298 + cps.add(mcp.getConnectPoint());
299 + }
300 + return cps;
301 + }
302 +
303 + /**
304 + * Find the Multicast Connect Point that contains the ConnectPoint.
305 + *
306 + * @param cp the regular ConnectPoint to match
307 + * @return the McastConnectPoint that contains cp or null if not found.
308 + */
309 + public McastConnectPoint findEgressConnectPoint(ConnectPoint cp) {
310 + for (McastConnectPoint mcp : this.egressPoints) {
311 + if (mcp.getConnectPoint().equals(cp)) {
312 + return mcp;
313 + }
314 + }
315 + return null;
316 + }
317 +
318 + /**
319 + * Remove specified interest from the given ConnectPoint.
320 + *
321 + * @param mcp connect point.
322 + * @param interest the protocol interested in this multicast stream
323 + * @return true if removed, false otherwise
324 + */
325 + public boolean removeInterest(McastConnectPoint mcp, McastConnectPoint.JoinSource interest) {
326 + checkNotNull(mcp);
327 + if (mcp.interest.contains(interest)) {
328 + mcp.interest.remove(interest);
329 + setDirty(true);
330 + return true;
331 + }
332 + return false;
333 + }
334 +
335 + /**
228 * Get the number of times the packet has been punted. 336 * Get the number of times the packet has been punted.
229 * 337 *
230 * @return the punt count 338 * @return the punt count
...@@ -264,7 +372,7 @@ public class McastRouteBase implements McastRoute { ...@@ -264,7 +372,7 @@ public class McastRouteBase implements McastRoute {
264 /** 372 /**
265 * Set the Intent key. 373 * Set the Intent key.
266 * 374 *
267 - * @param intent intent 375 + * @param intent the multicast intent
268 */ 376 */
269 @Override 377 @Override
270 public void setIntent(SinglePointToMultiPointIntent intent) { 378 public void setIntent(SinglePointToMultiPointIntent intent) {
...@@ -312,8 +420,8 @@ public class McastRouteBase implements McastRoute { ...@@ -312,8 +420,8 @@ public class McastRouteBase implements McastRoute {
312 out += (ingressPoint == null) ? "NULL" : ingressPoint.toString(); 420 out += (ingressPoint == null) ? "NULL" : ingressPoint.toString();
313 out += "\n\tegress: {\n"; 421 out += "\n\tegress: {\n";
314 if (egressPoints != null && !egressPoints.isEmpty()) { 422 if (egressPoints != null && !egressPoints.isEmpty()) {
315 - for (ConnectPoint eg : egressPoints) { 423 + for (McastConnectPoint eg : egressPoints) {
316 - out += "\t\t" + eg.toString() + "\n"; 424 + out += "\t\t" + eg.getConnectPoint().toString() + "\n";
317 } 425 }
318 } 426 }
319 out += ("\t}\n"); 427 out += ("\t}\n");
......
...@@ -157,7 +157,7 @@ public final class McastRouteTable { ...@@ -157,7 +157,7 @@ public final class McastRouteTable {
157 if (gpfx.isIp4()) { 157 if (gpfx.isIp4()) {
158 this.mrib4.put(gpfx, group); 158 this.mrib4.put(gpfx, group);
159 } else if (gpfx.isIp6() && ipv6Enabled) { 159 } else if (gpfx.isIp6() && ipv6Enabled) {
160 - this.mrib6.put(gpfx, group); 160 + this.mrib6.put(gpfx, group);
161 } 161 }
162 } 162 }
163 163
...@@ -259,7 +259,7 @@ public final class McastRouteTable { ...@@ -259,7 +259,7 @@ public final class McastRouteTable {
259 if (group.isIp4()) { 259 if (group.isIp4()) {
260 g = mrib4.get(group); 260 g = mrib4.get(group);
261 } else if (group.isIp6() && ipv6Enabled) { 261 } else if (group.isIp6() && ipv6Enabled) {
262 - g = mrib6.get(group); 262 + g = mrib6.get(group);
263 } 263 }
264 return g; 264 return g;
265 } 265 }
......