Julian Lawrence
Committed by Gerrit Code Review

Refactored Mfwd to use new mcastroutemanager

Change-Id: I7aca7f118221ed505aeb7fcace0ef9dccb468a34
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
22 <parent> 22 <parent>
23 <groupId>org.onosproject</groupId> 23 <groupId>org.onosproject</groupId>
24 <artifactId>onos-apps</artifactId> 24 <artifactId>onos-apps</artifactId>
25 - <version>1.5.0-SNAPSHOT</version> 25 + <version>1.4.0-SNAPSHOT</version>
26 <relativePath>../pom.xml</relativePath> 26 <relativePath>../pom.xml</relativePath>
27 </parent> 27 </parent>
28 28
......
...@@ -15,10 +15,15 @@ ...@@ -15,10 +15,15 @@
15 */ 15 */
16 package org.onosproject.mfwd.cli; 16 package org.onosproject.mfwd.cli;
17 17
18 +import org.apache.felix.scr.annotations.Reference;
19 +import org.apache.felix.scr.annotations.ReferenceCardinality;
18 import org.apache.karaf.shell.commands.Argument; 20 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 21 import org.apache.karaf.shell.commands.Command;
20 import org.onosproject.cli.AbstractShellCommand; 22 import org.onosproject.cli.AbstractShellCommand;
21 -import org.onosproject.mfwd.impl.McastRouteTable; 23 +import org.onosproject.mfwd.impl.McastForwarding;
24 +import org.onosproject.net.ConnectPoint;
25 +import org.onosproject.net.mcast.McastRoute;
26 +import org.onosproject.net.mcast.MulticastRouteService;
22 27
23 /** 28 /**
24 * Deletes a multicast route. 29 * Deletes a multicast route.
...@@ -27,6 +32,9 @@ import org.onosproject.mfwd.impl.McastRouteTable; ...@@ -27,6 +32,9 @@ import org.onosproject.mfwd.impl.McastRouteTable;
27 description = "Delete a multicast route flow") 32 description = "Delete a multicast route flow")
28 public class McastDeleteCommand extends AbstractShellCommand { 33 public class McastDeleteCommand extends AbstractShellCommand {
29 34
35 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
36 + MulticastRouteService mcastRouteManager = AbstractShellCommand.get(MulticastRouteService.class);
37 +
30 @Argument(index = 0, name = "sAddr", 38 @Argument(index = 0, name = "sAddr",
31 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry", 39 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
32 required = true, multiValued = false) 40 required = true, multiValued = false)
...@@ -46,23 +54,16 @@ public class McastDeleteCommand extends AbstractShellCommand { ...@@ -46,23 +54,16 @@ public class McastDeleteCommand extends AbstractShellCommand {
46 @Override 54 @Override
47 protected void execute() { 55 protected void execute() {
48 56
49 - boolean deleted = false; 57 + McastRoute mRoute = McastForwarding.createStaticRoute(sAddr, gAddr);
50 - McastRouteTable mrib = McastRouteTable.getInstance();
51 58
52 if (egressList == null) { 59 if (egressList == null) {
53 - mrib.removeRoute(sAddr, gAddr); 60 + mcastRouteManager.remove(mRoute);
54 - deleted = true;
55 } else { 61 } else {
56 // check list for validity before we begin to delete. 62 // check list for validity before we begin to delete.
57 for (String egress : egressList) { 63 for (String egress : egressList) {
58 - deleted = mrib.removeEgress(sAddr, gAddr, egress); 64 + ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress);
65 + mcastRouteManager.removeSink(mRoute, eCp);
59 } 66 }
60 } 67 }
61 -
62 - if (deleted) {
63 - print("Successful delete");
64 - } else {
65 - print("Failed to delete");
66 - }
67 } 68 }
68 } 69 }
......
...@@ -15,13 +15,15 @@ ...@@ -15,13 +15,15 @@
15 */ 15 */
16 package org.onosproject.mfwd.cli; 16 package org.onosproject.mfwd.cli;
17 17
18 +import org.apache.felix.scr.annotations.Reference;
19 +import org.apache.felix.scr.annotations.ReferenceCardinality;
18 import org.apache.karaf.shell.commands.Argument; 20 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 21 import org.apache.karaf.shell.commands.Command;
20 import org.onosproject.cli.AbstractShellCommand; 22 import org.onosproject.cli.AbstractShellCommand;
21 - 23 +import org.onosproject.mfwd.impl.McastForwarding;
22 -import org.onosproject.mfwd.impl.McastConnectPoint; 24 +import org.onosproject.net.ConnectPoint;
23 -import org.onosproject.mfwd.impl.McastRouteBase; 25 +import org.onosproject.net.mcast.McastRoute;
24 -import org.onosproject.mfwd.impl.McastRouteTable; 26 +import org.onosproject.net.mcast.MulticastRouteService;
25 27
26 /** 28 /**
27 * Installs a source, multicast group flow. 29 * Installs a source, multicast group flow.
...@@ -30,6 +32,9 @@ import org.onosproject.mfwd.impl.McastRouteTable; ...@@ -30,6 +32,9 @@ import org.onosproject.mfwd.impl.McastRouteTable;
30 description = "Installs a source, multicast group flow") 32 description = "Installs a source, multicast group flow")
31 public class McastJoinCommand extends AbstractShellCommand { 33 public class McastJoinCommand extends AbstractShellCommand {
32 34
35 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
36 + MulticastRouteService mcastRouteManager = AbstractShellCommand.get(MulticastRouteService.class);
37 +
33 @Argument(index = 0, name = "sAddr", 38 @Argument(index = 0, name = "sAddr",
34 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry", 39 description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
35 required = true, multiValued = false) 40 required = true, multiValued = false)
...@@ -41,31 +46,29 @@ public class McastJoinCommand extends AbstractShellCommand { ...@@ -41,31 +46,29 @@ public class McastJoinCommand extends AbstractShellCommand {
41 String gAddr = null; 46 String gAddr = null;
42 47
43 @Argument(index = 2, name = "ingressPort", 48 @Argument(index = 2, name = "ingressPort",
44 - description = "Ingress port and Egress ports", 49 + description = "Ingress port of:XXXXXXXXXX/XX",
45 required = false, multiValued = false) 50 required = false, multiValued = false)
46 String ingressPort = null; 51 String ingressPort = null;
47 52
48 @Argument(index = 3, name = "ports", 53 @Argument(index = 3, name = "ports",
49 - description = "Ingress port and Egress ports", 54 + description = "Egress ports of:XXXXXXXXXX/XX...",
50 required = false, multiValued = true) 55 required = false, multiValued = true)
51 String[] ports = null; 56 String[] ports = null;
52 57
53 @Override 58 @Override
54 protected void execute() { 59 protected void execute() {
55 - McastRouteTable mrib = McastRouteTable.getInstance();
56 - McastRouteBase mr = mrib.addRoute(sAddr, gAddr);
57 60
58 - // Port format "of:0000000000000023/4" 61 + McastRoute mRoute = McastForwarding.createStaticRoute(sAddr, gAddr);
59 - if (ingressPort != null) { 62 + mcastRouteManager.add(mRoute);
60 - String inCP = ingressPort;
61 - log.debug("Ingress port provided: " + inCP);
62 - mr.addIngressPoint(inCP);
63 - }
64 63
65 - for (int i = 0; i < ports.length; i++) { 64 + ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressPort);
66 - String egCP = ports[i]; 65 + mcastRouteManager.addSource(mRoute, ingress);
66 +
67 + for (String egCP : ports) {
67 log.debug("Egress port provided: " + egCP); 68 log.debug("Egress port provided: " + egCP);
68 - mr.addEgressPoint(egCP, McastConnectPoint.JoinSource.STATIC); 69 + ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP);
70 + mcastRouteManager.addSink(mRoute, egress);
71 +
69 } 72 }
70 print("Added the mcast route"); 73 print("Added the mcast route");
71 } 74 }
......
...@@ -15,15 +15,13 @@ ...@@ -15,15 +15,13 @@
15 */ 15 */
16 package org.onosproject.mfwd.cli; 16 package org.onosproject.mfwd.cli;
17 17
18 +import org.apache.felix.scr.annotations.Reference;
19 +import org.apache.felix.scr.annotations.ReferenceCardinality;
18 import org.apache.karaf.shell.commands.Command; 20 import org.apache.karaf.shell.commands.Command;
19 21
20 -import com.fasterxml.jackson.databind.node.ObjectNode;
21 -import com.fasterxml.jackson.databind.JsonNode;
22 -
23 import org.onosproject.cli.AbstractShellCommand; 22 import org.onosproject.cli.AbstractShellCommand;
24 -import org.onosproject.mfwd.impl.McastRouteTable;
25 -import org.onosproject.mfwd.impl.MRibCodec;
26 23
24 +import org.onosproject.net.mcast.MulticastRouteService;
27 import org.slf4j.Logger; 25 import org.slf4j.Logger;
28 import static org.slf4j.LoggerFactory.getLogger; 26 import static org.slf4j.LoggerFactory.getLogger;
29 27
...@@ -33,30 +31,15 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -33,30 +31,15 @@ import static org.slf4j.LoggerFactory.getLogger;
33 @Command(scope = "onos", name = "mcast-show", description = "Displays the source, multicast group flows") 31 @Command(scope = "onos", name = "mcast-show", description = "Displays the source, multicast group flows")
34 public class McastShowCommand extends AbstractShellCommand { 32 public class McastShowCommand extends AbstractShellCommand {
35 33
34 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
35 + MulticastRouteService mcastRouteManager = AbstractShellCommand.get(MulticastRouteService.class);
36 +
36 private final Logger log = getLogger(getClass()); 37 private final Logger log = getLogger(getClass());
37 private static final String MCAST_GROUP = "mcastgroup"; 38 private static final String MCAST_GROUP = "mcastgroup";
38 39
39 @Override 40 @Override
40 protected void execute() { 41 protected void execute() {
41 - McastRouteTable mrt = McastRouteTable.getInstance(); 42 + //TODO
42 - if (outputJson()) {
43 - print("%s", json(mrt));
44 - } else {
45 - printMrib4(mrt);
46 - }
47 } 43 }
48 44
49 - public JsonNode json(McastRouteTable mrt) {
50 - ObjectNode pushContent = new MRibCodec().encode(mrt , this);
51 - return pushContent;
52 - }
53 -
54 - /**
55 - * Displays multicast route table entries.
56 - *
57 - * @param mrt Mutlicast Route Table
58 - */
59 - protected void printMrib4(McastRouteTable mrt) {
60 - print(mrt.printMcastRouteTable());
61 - }
62 } 45 }
......
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.codec.CodecContext;
19 -import org.onosproject.codec.JsonCodec;
20 -
21 -import org.onlab.packet.IpPrefix;
22 -
23 -import java.util.Set;
24 -import java.util.Map;
25 -import java.util.Collection;
26 -import java.util.Iterator;
27 -import java.util.Optional;
28 -
29 -import com.fasterxml.jackson.databind.node.ArrayNode;
30 -import com.fasterxml.jackson.databind.node.ObjectNode;
31 -import com.fasterxml.jackson.databind.JsonNode;
32 -import com.fasterxml.jackson.databind.node.JsonNodeFactory;
33 -
34 -import org.slf4j.Logger;
35 -import static org.slf4j.LoggerFactory.getLogger;
36 -
37 -/**
38 - * Encode and Decode the Multicast Route Table in JSON for CLI and REST commands.
39 - */
40 -public class MRibCodec extends JsonCodec<McastRouteTable> {
41 -
42 - private final Logger log = getLogger(getClass());
43 - private static final String SOURCE_ADDRESS = "sourceAddress";
44 - private static final String GROUP_ADDRESS = "groupAddress";
45 - private static final String INGRESS_POINT = "ingressPoint";
46 - private static final String EGRESS_POINT = "egressPoint";
47 - private static final String MCASTCONNECTPOINT = "McastConnectPoint";
48 - private static final String ELEMENTID = "elementId";
49 - private static final String PORTNUMBER = "portNumber";
50 - private static final String MCAST_GROUP = "mcastGroup";
51 -
52 - /**
53 - * Encode the MRIB into json format.
54 - *
55 - * @param mcastRouteTable McastRouteTable
56 - * @param context CodecContext
57 - * @return result ObjectNode
58 - */
59 - @Override
60 - public ObjectNode encode(McastRouteTable mcastRouteTable, CodecContext context) {
61 -
62 - final JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
63 - final ObjectNode macastRouteTabNode = nodeFactory.objectNode();
64 - ArrayNode mcastGroupNode = context.mapper().createArrayNode();
65 - Optional<McastRouteTable> mcastRouteTabOpt = Optional.ofNullable(mcastRouteTable);
66 -
67 - //checking whether the McastRouteTable is present.
68 - if (mcastRouteTabOpt.isPresent()) {
69 - Map<IpPrefix, McastRouteGroup> mrib4 = mcastRouteTabOpt.get().getMrib4();
70 - Optional<Map<IpPrefix, McastRouteGroup>> mrib4Opt = Optional.ofNullable(mrib4);
71 -
72 - //checking whether the mrib4 is present.
73 - if (mrib4Opt.isPresent()) {
74 -
75 - for (McastRouteGroup mg : mrib4Opt.get().values()) {
76 - Collection<McastRouteSource> mcastRoute = mg.getSources().values();
77 - Optional<Collection<McastRouteSource>> mcastRouteOpt = Optional.ofNullable(mcastRoute);
78 -
79 - //checking whether the McastRouteSource List is present.
80 - if (mcastRouteOpt.isPresent()) {
81 - for (McastRouteSource mcastRouteSource : mcastRouteOpt.get()) {
82 - mcastGroupNode.add(createMcastGroupNode(mcastRouteSource, context));
83 - }
84 - macastRouteTabNode.put(MCAST_GROUP, mcastGroupNode);
85 - }
86 - }
87 - }
88 - }
89 - return macastRouteTabNode;
90 - }
91 - /**
92 - * Method for creating the McastGroup object node.
93 - *
94 - * @param mcastRouteSource McastRouteSource
95 - */
96 - private ObjectNode createMcastGroupNode(McastRouteSource mcastRouteSource, CodecContext context) {
97 -
98 - final ObjectNode mcastGroupNode = context.mapper().createObjectNode();
99 - final ObjectNode ingressNode = context.mapper().createObjectNode();
100 - final ObjectNode egressNode = context.mapper().createObjectNode();
101 - final ArrayNode jsonLabelIds = context.mapper().createArrayNode();
102 - final String sAddr = mcastRouteSource.getSaddr().toString();
103 - final String gAddr = mcastRouteSource.getGaddr().toString();
104 -
105 - Optional<String> saddrOpt = Optional.ofNullable(sAddr);
106 - Optional<String> gaddrOpt = Optional.ofNullable(gAddr);
107 -
108 - //checking source address and group address are present.
109 - if (saddrOpt.isPresent() && gaddrOpt.isPresent()) {
110 - mcastGroupNode.put(SOURCE_ADDRESS, saddrOpt.get().toString());
111 - mcastGroupNode.put(GROUP_ADDRESS, gaddrOpt.get().toString());
112 - McastConnectPoint mcastIngCP = mcastRouteSource.getIngressPoint();
113 - Optional<McastConnectPoint> mcastIngCPOpt = Optional.ofNullable(mcastIngCP);
114 -
115 - //checking whether the ingress connection point is present.
116 - if (mcastIngCPOpt.isPresent()) {
117 - ingressNode.put(MCASTCONNECTPOINT, mcastConnectPoint(mcastIngCPOpt.get(), context));
118 - }
119 -
120 - mcastGroupNode.put(INGRESS_POINT , ingressNode);
121 - Set<McastConnectPoint> mcastEgCPSet = mcastRouteSource.getEgressPoints();
122 - Optional<Set<McastConnectPoint>> mcastEgCPOpt = Optional.ofNullable(mcastEgCPSet);
123 -
124 - //checking whether the egress connection points are present.
125 - if (mcastEgCPOpt.isPresent()) {
126 - for (final McastConnectPoint mcastConnectPoint : mcastEgCPOpt.get()) {
127 - jsonLabelIds.add(mcastConnectPoint(mcastConnectPoint, context));
128 - }
129 - }
130 -
131 - egressNode.put(MCASTCONNECTPOINT , jsonLabelIds);
132 - mcastGroupNode.put(EGRESS_POINT , egressNode);
133 - }
134 - return mcastGroupNode;
135 - }
136 -
137 - /**
138 - * Method for creating the McastConnectPoint object node.
139 - *
140 - * @param mcastConnectPoint McastConnectPoint
141 - * @param context CodecContext
142 - * @return mcastCpNode ObjectNode
143 - */
144 - private ObjectNode mcastConnectPoint(McastConnectPoint mcastConnectPoint, CodecContext context) {
145 - final ObjectNode mcastCpNode = context.mapper().createObjectNode();
146 - mcastCpNode.put(ELEMENTID , mcastConnectPoint.getConnectPoint().elementId().toString());
147 - mcastCpNode.put(PORTNUMBER , mcastConnectPoint.getConnectPoint().port().toLong());
148 - return mcastCpNode;
149 - }
150 -
151 - /**
152 - * Decode json format and insert into the flow table.
153 - *
154 - * @param json ObjectNode
155 - * @param context CodecContext
156 - * @return mr McastRouteBase
157 - */
158 - @Override
159 - public McastRouteTable decode(ObjectNode json, CodecContext context) {
160 -
161 - String macAddr = null;
162 - String portNo = null;
163 - String sAddr = json.path(SOURCE_ADDRESS).asText();
164 - String gAddr = json.path(GROUP_ADDRESS).asText();
165 - JsonNode inPntObjNode = (JsonNode) json.path(INGRESS_POINT);
166 - JsonNode egPntArrNode = (JsonNode) json.path(EGRESS_POINT);
167 -
168 - log.debug("sAddr :" + sAddr + " gAddr :" + gAddr + " inPntObjNode :" + inPntObjNode);
169 - log.debug("egPntArrNode :" + egPntArrNode.toString());
170 -
171 - McastRouteTable mrib = McastRouteTable.getInstance();
172 - McastRouteBase mr = mrib.addRoute(sAddr, gAddr);
173 - Optional<JsonNode> inPntOpt = Optional.ofNullable(inPntObjNode);
174 -
175 - if (inPntOpt.isPresent()) {
176 -
177 - JsonNode inMcastCP = inPntOpt.get().path(MCASTCONNECTPOINT);
178 - Optional<JsonNode> inCpOpt = Optional.ofNullable(inMcastCP);
179 -
180 - if (inCpOpt.isPresent()) {
181 - macAddr = inCpOpt.get().path(ELEMENTID).asText();
182 - portNo = inCpOpt.get().path(PORTNUMBER).asText();
183 - mr.addIngressPoint(macAddr + "/" + Long.parseLong(portNo));
184 - }
185 - }
186 -
187 - Optional<JsonNode> egPntOpt = Optional.ofNullable(egPntArrNode);
188 -
189 - if (egPntOpt.isPresent()) {
190 - JsonNode egMcastCP = egPntOpt.get().path(MCASTCONNECTPOINT);
191 - Optional<JsonNode> egMcCpOpt = Optional.ofNullable(egMcastCP);
192 -
193 - if (egMcCpOpt.isPresent()) {
194 - Iterator<JsonNode> egCpIt = egMcCpOpt.get().elements();
195 -
196 - while (egCpIt.hasNext()) {
197 -
198 - JsonNode egMcastCPObj = egCpIt.next();
199 - Optional<JsonNode> egMcCpObOpt = Optional.ofNullable(egMcastCPObj);
200 - if (egMcCpObOpt.isPresent()) {
201 - macAddr = egMcCpObOpt.get().path(ELEMENTID).asText();
202 - portNo = egMcCpObOpt.get().path(PORTNUMBER).asText();
203 - log.debug("macAddr egPort : " + macAddr + " portNo egPort :" + portNo);
204 - mr.addEgressPoint(macAddr + "/" + Long.parseLong(portNo), McastConnectPoint.JoinSource.STATIC);
205 - }
206 - }
207 - }
208 - }
209 - return mrib;
210 - }
211 -}
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 -}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.mfwd.impl; 16 package org.onosproject.mfwd.impl;
17 17
18 +import static com.google.common.base.Preconditions.checkNotNull;
18 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
19 20
20 import org.apache.felix.scr.annotations.Activate; 21 import org.apache.felix.scr.annotations.Activate;
...@@ -35,6 +36,8 @@ import org.onosproject.net.flow.DefaultTrafficSelector; ...@@ -35,6 +36,8 @@ import org.onosproject.net.flow.DefaultTrafficSelector;
35 import org.onosproject.net.flow.DefaultTrafficTreatment; 36 import org.onosproject.net.flow.DefaultTrafficTreatment;
36 import org.onosproject.net.flow.TrafficSelector; 37 import org.onosproject.net.flow.TrafficSelector;
37 import org.onosproject.net.flow.TrafficTreatment; 38 import org.onosproject.net.flow.TrafficTreatment;
39 +import org.onosproject.net.mcast.MulticastRouteService;
40 +import org.onosproject.net.mcast.McastRoute;
38 import org.onosproject.net.packet.DefaultOutboundPacket; 41 import org.onosproject.net.packet.DefaultOutboundPacket;
39 import org.onosproject.net.packet.InboundPacket; 42 import org.onosproject.net.packet.InboundPacket;
40 import org.onosproject.net.packet.OutboundPacket; 43 import org.onosproject.net.packet.OutboundPacket;
...@@ -44,8 +47,12 @@ import org.onosproject.net.packet.PacketProcessor; ...@@ -44,8 +47,12 @@ import org.onosproject.net.packet.PacketProcessor;
44 import org.onosproject.net.packet.PacketService; 47 import org.onosproject.net.packet.PacketService;
45 import org.slf4j.Logger; 48 import org.slf4j.Logger;
46 49
50 +import java.util.ArrayList;
51 +
47 /** 52 /**
48 - * WORK-IN-PROGRESS: The multicast forwarding application using intent framework. 53 + * The multicast forwarding component. This component is responsible for
54 + * handling live multicast traffic by modifying multicast state and forwarding
55 + * packets that do not yet have state installed.
49 */ 56 */
50 @Component(immediate = true) 57 @Component(immediate = true)
51 public class McastForwarding { 58 public class McastForwarding {
...@@ -59,8 +66,12 @@ public class McastForwarding { ...@@ -59,8 +66,12 @@ public class McastForwarding {
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 66 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected CoreService coreService; 67 protected CoreService coreService;
61 68
69 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 + protected MulticastRouteService mcastRouteManager;
71 +
72 +
73 +
62 private ReactivePacketProcessor processor = new ReactivePacketProcessor(); 74 private ReactivePacketProcessor processor = new ReactivePacketProcessor();
63 - private McastRouteTable mrib;
64 private static ApplicationId appId; 75 private static ApplicationId appId;
65 76
66 /** 77 /**
...@@ -76,9 +87,9 @@ public class McastForwarding { ...@@ -76,9 +87,9 @@ public class McastForwarding {
76 TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); 87 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
77 selector.matchEthType(Ethernet.TYPE_IPV4); 88 selector.matchEthType(Ethernet.TYPE_IPV4);
78 selector.matchIPDst(mcast); 89 selector.matchIPDst(mcast);
90 +
79 packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); 91 packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId);
80 92
81 - mrib = McastRouteTable.getInstance();
82 log.info("Started"); 93 log.info("Started");
83 } 94 }
84 95
...@@ -137,8 +148,8 @@ public class McastForwarding { ...@@ -137,8 +148,8 @@ public class McastForwarding {
137 } 148 }
138 149
139 IPv4 ip = (IPv4) ethPkt.getPayload(); 150 IPv4 ip = (IPv4) ethPkt.getPayload();
140 - IpAddress gaddr = IpAddress.valueOf(ip.getDestinationAddress());
141 IpAddress saddr = Ip4Address.valueOf(ip.getSourceAddress()); 151 IpAddress saddr = Ip4Address.valueOf(ip.getSourceAddress());
152 + IpAddress gaddr = IpAddress.valueOf(ip.getDestinationAddress());
142 153
143 log.debug("Packet ({}, {}) has been punted\n" + 154 log.debug("Packet ({}, {}) has been punted\n" +
144 "\tingress port: {}\n", 155 "\tingress port: {}\n",
...@@ -146,70 +157,37 @@ public class McastForwarding { ...@@ -146,70 +157,37 @@ public class McastForwarding {
146 gaddr.toString(), 157 gaddr.toString(),
147 context.inPacket().receivedFrom().toString()); 158 context.inPacket().receivedFrom().toString());
148 159
149 - if (!mcast.contains(gaddr)) { 160 + // Don't allow PIM/IGMP packets to be handled here.
150 - // Yikes, this is a bad group address 161 + byte proto = ip.getProtocol();
151 - return; 162 + if (proto == IPv4.PROTOCOL_PIM || proto == IPv4.PROTOCOL_IGMP) {
152 - }
153 -
154 - if (mcast.contains(saddr)) {
155 - // Yikes, the source address is multicast
156 return; 163 return;
157 } 164 }
158 165
159 IpPrefix spfx = IpPrefix.valueOf(saddr, 32); 166 IpPrefix spfx = IpPrefix.valueOf(saddr, 32);
160 IpPrefix gpfx = IpPrefix.valueOf(gaddr, 32); 167 IpPrefix gpfx = IpPrefix.valueOf(gaddr, 32);
161 168
162 - /* 169 + // TODO do we want to add a type for Mcast?
163 - * Do a best match lookup on the (s, g) of the packet. If an entry does 170 + McastRoute mRoute = new McastRoute(spfx, gpfx, McastRoute.Type.STATIC);
164 - * not exist create one and store it's incoming connect point.
165 - *
166 - * The connect point is deviceId / portId that the packet entered
167 - * the SDN network. This differs from traditional mcast where the
168 - * ingress port would be a specific device.
169 - */
170 - McastRoute entry = mrib.findBestMatch(spfx, gpfx);
171 - if (entry == null || entry.getSaddr().address().isZero()) {
172 -
173 - /*
174 - * Create an entry that we can fast drop.
175 - */
176 - entry = mrib.addRoute(spfx, gpfx);
177 - entry.addIngressPoint(context.inPacket().receivedFrom());
178 - }
179 171
180 - /* 172 + ConnectPoint ingress = mcastRouteManager.fetchSource(mRoute);
181 - * TODO: If we do not have an ingress or any egress connect points we
182 - * should set up a fast drop entry.
183 - */
184 - if (entry.getIngressPoint() == null) {
185 - return;
186 - }
187 173
188 - if (entry.getEgressPoints().isEmpty()) { 174 + // An ingress port already exists. Log error.
175 + if (ingress != null) {
176 + log.error(McastForwarding.class.getSimpleName() + " received packet which already has a route.");
189 return; 177 return;
178 + } else {
179 + //add ingress port
180 + mcastRouteManager.addSource(mRoute, pkt.receivedFrom());
190 } 181 }
191 182
192 - /* 183 + ArrayList<ConnectPoint> egressList = (ArrayList<ConnectPoint>) mcastRouteManager.fetchSinks(mRoute);
193 - * This is odd, we should not have received a punted packet if an 184 + //If there are no egress ports set return, otherwise forward the packets to their expected port.
194 - * intent was installed unless the intent was not installed 185 + if (egressList.size() == 0) {
195 - * correctly. However, we are seeing packets get punted after
196 - * the intent has been installed.
197 - *
198 - * Therefore we are going to forward the packets even if they
199 - * should have already been forwarded by the intent fabric.
200 - */
201 - if (entry.getIntentKey() != null) {
202 return; 186 return;
203 } 187 }
204 188
205 - entry.setIntent();
206 - McastIntentManager im = McastIntentManager.getInstance();
207 - im.setIntent(entry);
208 -
209 - entry.incrementPuntCount();
210 -
211 // Send the pack out each of the egress devices & port 189 // Send the pack out each of the egress devices & port
212 - forwardPacketToDst(context, entry); 190 + forwardPacketToDst(context, egressList);
213 } 191 }
214 } 192 }
215 193
...@@ -217,12 +195,12 @@ public class McastForwarding { ...@@ -217,12 +195,12 @@ public class McastForwarding {
217 * Forward the packet to it's multicast destinations. 195 * Forward the packet to it's multicast destinations.
218 * 196 *
219 * @param context The packet context 197 * @param context The packet context
220 - * @param entry The multicast route entry matching this packet 198 + * @param egressList The list of egress ports which the multicast packet is intended for.
221 */ 199 */
222 - private void forwardPacketToDst(PacketContext context, McastRoute entry) { 200 + private void forwardPacketToDst(PacketContext context, ArrayList<ConnectPoint> egressList) {
223 201
224 // Send the pack out each of the respective egress ports 202 // Send the pack out each of the respective egress ports
225 - for (ConnectPoint egress : entry.getEgressConnectPoints()) { 203 + for (ConnectPoint egress : egressList) {
226 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 204 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
227 .setOutput(egress.port()).build(); 205 .setOutput(egress.port()).build();
228 206
...@@ -234,4 +212,19 @@ public class McastForwarding { ...@@ -234,4 +212,19 @@ public class McastForwarding {
234 packetService.emit(packet); 212 packetService.emit(packet);
235 } 213 }
236 } 214 }
215 +
216 + public static McastRoute createStaticRoute(String source, String group) {
217 + checkNotNull(source, "Must provide a source");
218 + checkNotNull(group, "Must provide a group");
219 + IpPrefix ipSource = IpPrefix.valueOf(source);
220 + IpPrefix ipGroup = IpPrefix.valueOf(group);
221 + return createStaticcreateRoute(ipSource, ipGroup);
222 + }
223 +
224 + public static McastRoute createStaticcreateRoute(IpPrefix source, IpPrefix group) {
225 + checkNotNull(source, "Must provide a source");
226 + checkNotNull(group, "Must provide a group");
227 + McastRoute.Type type = McastRoute.Type.STATIC;
228 + return new McastRoute(source, group, type);
229 + }
237 } 230 }
......
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.apache.felix.scr.annotations.Activate;
19 -import org.apache.felix.scr.annotations.Component;
20 -import org.apache.felix.scr.annotations.Service;
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.onlab.packet.Ethernet;
25 -import org.onosproject.net.intent.Intent;
26 -import org.onosproject.net.intent.SinglePointToMultiPointIntent;
27 -import org.onosproject.net.intent.IntentService;
28 -import org.onosproject.net.flow.DefaultTrafficSelector;
29 -import org.onosproject.net.flow.DefaultTrafficTreatment;
30 -import org.onosproject.net.flow.TrafficSelector;
31 -import org.onosproject.net.flow.TrafficTreatment;
32 -
33 -@Component(immediate = true)
34 -@Service(value = org.onosproject.mfwd.impl.McastIntentManager.class)
35 -public class McastIntentManager {
36 -
37 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
38 - protected IntentService intentService;
39 -
40 - private static McastIntentManager instance;
41 -
42 - public McastIntentManager() {
43 - instance = this;
44 - }
45 -
46 - /**
47 - * Active this component.
48 - */
49 - @Activate
50 - public void activate() { }
51 -
52 - /**
53 - * Deactivate this component.
54 - */
55 - @Deactivate
56 - public void deactivate() {
57 - withdrawAllIntents();
58 - }
59 -
60 - /**
61 - * Get instance of this intentManager.
62 - *
63 - * @return the instance of this intent manager.
64 - */
65 - public static McastIntentManager getInstance() {
66 - if (instance == null) {
67 - instance = new McastIntentManager();
68 - }
69 - return instance;
70 - }
71 -
72 - /**
73 - * Install the PointToMultipoint forwarding intent.
74 - *
75 - * @param mroute multicast route entry
76 - * @return the intent that has been set or null otherwise
77 - */
78 - public SinglePointToMultiPointIntent setIntent(McastRoute mroute) {
79 - TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
80 - TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
81 -
82 - if (mroute.getIngressPoint() == null) {
83 - return null;
84 - }
85 -
86 - /*
87 - * Match the group AND source addresses. We will also check ether type to
88 - * determine if we are doing ipv4 or ipv6.
89 - *
90 - * If we really wanted to be pendantic we could put in a
91 - * condition to make sure the ethernet MAC address was also
92 - * mcast.
93 - */
94 - selector.matchEthType(Ethernet.TYPE_IPV4)
95 - .matchIPDst(mroute.getGaddr())
96 - .matchIPSrc(mroute.getSaddr());
97 -
98 -
99 - SinglePointToMultiPointIntent.Builder builder = SinglePointToMultiPointIntent.builder()
100 - .appId(McastForwarding.getAppId())
101 - .selector(selector.build())
102 - .treatment(treatment)
103 - .ingressPoint(mroute.getIngressPoint().getConnectPoint());
104 -
105 - // allowing intent to be pushed without egress points means we can drop packets.
106 - if (!mroute.getEgressPoints().isEmpty()) {
107 - builder.egressPoints(mroute.getEgressConnectPoints());
108 - }
109 -
110 - SinglePointToMultiPointIntent intent = builder.build();
111 - intentService.submit(intent);
112 - mroute.setDirty(false);
113 -
114 - return intent;
115 - }
116 -
117 - /**
118 - * Withdraw the intent represented by this route.
119 - *
120 - * @param mroute the mcast route whose intent we want to remove
121 - */
122 - public void withdrawIntent(McastRoute mroute) {
123 - Intent intent = intentService.getIntent(mroute.getIntentKey());
124 - intentService.withdraw(intent);
125 - mroute.setDirty(false);
126 - }
127 -
128 - /**
129 - * Withdraw all intents.
130 - *
131 - * This will be called from the deactivate method so we don't leave
132 - * a mess behind us after we leave.
133 - */
134 - public void withdrawAllIntents() {
135 - for (Intent intent : intentService.getIntents()) {
136 - intentService.withdraw(intent);
137 - }
138 - }
139 -}
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.onlab.packet.IpPrefix;
19 -import org.onosproject.net.ConnectPoint;
20 -import org.onosproject.net.intent.Key;
21 -import org.onosproject.net.intent.SinglePointToMultiPointIntent;
22 -
23 -import java.util.Set;
24 -
25 -/**
26 - * This McastRouteBase interface is implemented by the McastRouteBase class which
27 - * in turn acts as the base class for both the McastRouteGroup and McastRouteSource.
28 - */
29 -interface McastRoute {
30 -
31 - /**
32 - * Gets the group addresses.
33 - *
34 - * @return group address
35 - */
36 - public IpPrefix getGaddr();
37 -
38 - /**
39 - * Gets the source address.
40 - *
41 - * @return the source address
42 - */
43 - public IpPrefix getSaddr();
44 -
45 - /**
46 - * Determines if this is an IPv4 multicast route.
47 - *
48 - * @return true if it is an IPv4 route
49 - */
50 - public boolean isIp4();
51 -
52 - /**
53 - * Determines if this is an IPv6 multicast route.
54 - *
55 - * @return true if it is an IPv6 route
56 - */
57 - public boolean isIp6();
58 -
59 - /**
60 - * Get the dirty state.
61 - *
62 - * @return whether this route is dirty or not.
63 - */
64 - public boolean getDirty();
65 -
66 - /**
67 - * Set the dirty state to indicate that something changed.
68 - * This may require an update to the flow tables (intents).
69 - *
70 - * @param dirty set the dirty bit
71 - */
72 - public void setDirty(boolean dirty);
73 -
74 - /**
75 - * Add the ingress ConnectPoint.
76 - *
77 - * @param cpstr string representing a ConnectPoint
78 - * @return whether ingress has been added, only add if ingressPoint is null
79 - */
80 - public boolean addIngressPoint(String cpstr);
81 -
82 - /**
83 - * Add the ingress ConnectPoint.
84 - *
85 - * @param cp the ConnectPoint of incoming traffic.
86 - * @return whether ingress has been added, only add if ingressPoint is null
87 - */
88 - public boolean addIngressPoint(ConnectPoint cp);
89 -
90 - /**
91 - * Get the ingress connect point.
92 - *
93 - * @return the ingress connect point
94 - */
95 - public McastConnectPoint getIngressPoint();
96 -
97 - /**
98 - * Add an egress connect point.
99 - *
100 - * @param cp the egress McastConnectPoint to be added
101 - * @return return the McastConnectPoint
102 - */
103 - public McastConnectPoint addEgressPoint(ConnectPoint cp);
104 -
105 - /**
106 - * Add an egress connect point.
107 - *
108 - * @param connectPoint deviceId/portNum
109 - * @return return the McastConnectPoint
110 - */
111 - public McastConnectPoint addEgressPoint(String connectPoint);
112 -
113 - /**
114 - * Add an egress connect point.
115 - *
116 - * @param cp the egress McastConnectPoint to be added
117 - * @param interest the protocol that has shown interest in this route
118 - * @return return the McastConnectPoint
119 - */
120 - public McastConnectPoint addEgressPoint(ConnectPoint cp, McastConnectPoint.JoinSource interest);
121 -
122 - /**
123 - * Add an egress connect point.
124 - *
125 - * @param connectPoint deviceId/portNum
126 - * @param interest the protocol that has shown interest in this route
127 - * @return return the McastConnectPoint
128 - */
129 - public McastConnectPoint addEgressPoint(String connectPoint, McastConnectPoint.JoinSource interest);
130 -
131 - /**
132 - * Get the egress connect points.
133 - *
134 - * @return a set of egress connect points
135 - */
136 - public Set<McastConnectPoint> getEgressPoints();
137 -
138 - /**
139 - * Get the egress connect points.
140 - *
141 - * @return a set of egress connect points
142 - */
143 - public Set<ConnectPoint> getEgressConnectPoints();
144 -
145 - /**
146 - * Find the egress connect point if it exists.
147 - *
148 - * @param cp ConnectPoint to search for
149 - * @return the connect point when found, null otherwise.
150 - */
151 - public McastConnectPoint findEgressConnectPoint(ConnectPoint cp);
152 -
153 - /**
154 - * remove Interest from a McastConnectPoint.
155 - *
156 - * @param mcp connect point.
157 - * @param interest the protocol interested in this multicast stream
158 - * @return whether or not interest was removed
159 - */
160 - public boolean removeInterest(McastConnectPoint mcp, McastConnectPoint.JoinSource interest);
161 -
162 - /**
163 - * Increment the punt count.
164 - */
165 - public void incrementPuntCount();
166 -
167 - /**
168 - * Get the punt count.
169 - *
170 - * @return the punt count
171 - */
172 - public int getPuntCount();
173 -
174 - /**
175 - * Have the McastIntentManager create an intent, attempt to
176 - * install the intent and then save the key.
177 - */
178 - public void setIntent();
179 -
180 - /**
181 - * Set the Intent key.
182 - *
183 - * @param intent intent
184 - */
185 - public void setIntent(SinglePointToMultiPointIntent intent);
186 -
187 - /**
188 - * Withdraw the intent if it has been installed.
189 - */
190 - public void withdrawIntent();
191 -
192 - /**
193 - * Get the intent key.
194 - *
195 - * @return the intentKey
196 - */
197 - public Key getIntentKey();
198 -
199 - /**
200 - * Pretty print the the route.
201 - *
202 - * @return a pretty string
203 - */
204 - public String toString();
205 -}
...\ No newline at end of file ...\ No newline at end of file
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 static com.google.common.base.Preconditions.checkNotNull;
19 -
20 -import org.onlab.packet.IpPrefix;
21 -import org.onosproject.net.ConnectPoint;
22 -import org.onosproject.net.intent.SinglePointToMultiPointIntent;
23 -import org.onosproject.net.intent.Key;
24 -
25 -import java.util.Set;
26 -import java.util.HashSet;
27 -
28 -/**
29 - * McastRouteBase base class for McastRouteGroup and McastRouteSource.
30 - */
31 -public class McastRouteBase implements McastRoute {
32 - protected final IpPrefix gaddr;
33 - protected final IpPrefix saddr;
34 -
35 - protected McastConnectPoint ingressPoint;
36 - protected Set<McastConnectPoint> egressPoints;
37 -
38 - protected boolean isGroup = false;
39 -
40 - protected boolean dirty = false;
41 -
42 - /**
43 - * How may times has this packet been punted.
44 - */
45 - private int puntCount = 0;
46 -
47 - /**
48 - * If the intentKey is null that means no intent has
49 - * been installed.
50 - */
51 - protected Key intentKey = null;
52 -
53 - /**
54 - * Create a multicast route. This is the parent class for both the Group
55 - * and the source.
56 - *
57 - * @param saddr source address
58 - * @param gaddr multicast group address
59 - */
60 - public McastRouteBase(String saddr, String gaddr) {
61 - this.gaddr = IpPrefix.valueOf(checkNotNull(gaddr));
62 - if (saddr == null || saddr.equals("*")) {
63 - this.saddr = IpPrefix.valueOf(0, 0);
64 - } else {
65 - this.saddr = IpPrefix.valueOf(checkNotNull(gaddr));
66 - }
67 - this.init();
68 - }
69 -
70 - /**
71 - * Create a multicast group table entry.
72 - * @param gaddr multicast group address
73 - */
74 - public McastRouteBase(String gaddr) {
75 - this("*", gaddr);
76 - }
77 -
78 - /**
79 - * Set the source and group address value of a (*, G) group.
80 - *
81 - * @param gpfx the group prefix address
82 - */
83 - public McastRouteBase(IpPrefix gpfx) {
84 - this(IpPrefix.valueOf(0, 0), gpfx);
85 - }
86 -
87 - /**
88 - * Create a multicast route constructor.
89 - *
90 - * @param saddr source address
91 - * @param gaddr group address
92 - */
93 - public McastRouteBase(IpPrefix saddr, IpPrefix gaddr) {
94 - this.saddr = checkNotNull(saddr);
95 - this.gaddr = checkNotNull(gaddr);
96 -
97 - this.init();
98 - }
99 -
100 - private void init() {
101 - this.isGroup = (this.saddr.prefixLength() == 0);
102 - this.ingressPoint = null;
103 - this.egressPoints = new HashSet();
104 - }
105 -
106 - /**
107 - * Get the multicast group address.
108 - *
109 - * @return the multicast group address
110 - */
111 - @Override
112 - public IpPrefix getGaddr() {
113 - return gaddr;
114 - }
115 -
116 - /**
117 - * Get the multicast source address.
118 - *
119 - * @return the multicast source address
120 - */
121 - @Override
122 - public IpPrefix getSaddr() {
123 - return saddr;
124 - }
125 -
126 - /**
127 - * Is this an IPv4 multicast route.
128 - *
129 - * @return true if it is an IPv4 route
130 - */
131 - @Override
132 - public boolean isIp4() {
133 - return gaddr.isIp4();
134 - }
135 -
136 - /**
137 - * Is this an IPv6 multicast route.
138 - *
139 - * @return true if it is an IPv6 route
140 - */
141 - @Override
142 - public boolean isIp6() {
143 - return gaddr.isIp6();
144 - }
145 -
146 - /**
147 - * Is this a multicast group route?
148 - *
149 - * @return true if it is a multicast group route.
150 - */
151 - public boolean isGroup() {
152 - return isGroup;
153 - }
154 -
155 - /**
156 - * @return true if this is (S, G) false if it (*, G).
157 - */
158 - public boolean isSource() {
159 - return (!isGroup);
160 - }
161 -
162 - /**
163 - * Get the dirty state.
164 - *
165 - * @return whether this route is dirty or not.
166 - */
167 - public boolean getDirty() {
168 - return this.dirty;
169 - }
170 -
171 - /**
172 - * Set the dirty state to indicate that something changed.
173 - * This may require an update to the flow tables (intents).
174 - *
175 - * @param dirty set the dirty bit
176 - */
177 - public void setDirty(boolean dirty) {
178 - this.dirty = dirty;
179 - }
180 -
181 - /**
182 - * Add an ingress point to this route.
183 - *
184 - * @param ingress incoming connect point
185 - * @return whether ingress has been added, only add if ingressPoint is null
186 - */
187 - public boolean addIngressPoint(ConnectPoint ingress) {
188 -
189 - // Do NOT add the ingressPoint if it is not null.
190 - if (this.ingressPoint != null) {
191 - // TODO: Log an warning.
192 - return false;
193 - }
194 - this.ingressPoint = new McastConnectPoint(checkNotNull(ingress));
195 - setDirty(true);
196 - return true;
197 - }
198 -
199 - /**
200 - * Add or modify the ingress connect point.
201 - *
202 - * @param connectPoint string switch device Id
203 - * @return whether ingress has been added, only add if ingressPoint is null
204 - */
205 - public boolean addIngressPoint(String connectPoint) {
206 -
207 - if (this.ingressPoint != null) {
208 - // TODO: log a warning.
209 - return false;
210 - }
211 - ConnectPoint cp = ConnectPoint.deviceConnectPoint(checkNotNull(connectPoint));
212 - return this.addIngressPoint(cp);
213 - }
214 -
215 - /**
216 - * Get the ingress McastConnectPoint.
217 - *
218 - * @return the ingress McastConnectPoint
219 - */
220 - public McastConnectPoint getIngressPoint() {
221 - return this.ingressPoint;
222 - }
223 -
224 - /**
225 - * Add an egress McastConnectPoint.
226 - *
227 - * @param cp egress connect point
228 - * @return return the McastConnectPoint
229 - */
230 - public McastConnectPoint addEgressPoint(ConnectPoint cp) {
231 - McastConnectPoint mcp = this.findEgressConnectPoint(cp);
232 - if (mcp == null) {
233 - mcp = new McastConnectPoint(checkNotNull(cp));
234 - egressPoints.add(mcp);
235 - setDirty(true);
236 - }
237 - return mcp;
238 - }
239 -
240 - /**
241 - * Add an egress connect point from a string.
242 - *
243 - * @param connectPoint string representing a connect point
244 - * @return the MulticastConnectPoint
245 - */
246 - public McastConnectPoint addEgressPoint(String connectPoint) {
247 - checkNotNull(connectPoint);
248 - return this.addEgressPoint(ConnectPoint.deviceConnectPoint(connectPoint));
249 - }
250 -
251 - /**
252 - * Add an egress McastConnectPoint.
253 - *
254 - * @param cp the egress connect point
255 - * @param interest the source of interest for mcast traffic
256 - */
257 - public McastConnectPoint addEgressPoint(ConnectPoint cp, McastConnectPoint.JoinSource interest) {
258 - checkNotNull(cp);
259 - checkNotNull(interest);
260 - McastConnectPoint mcp = this.addEgressPoint(cp);
261 - if (mcp != null) {
262 - mcp.interest.add(interest);
263 - setDirty(true);
264 - }
265 - return mcp;
266 - }
267 -
268 - /**
269 - * Remove an egress from McastConnectPoint.
270 - *
271 - * @param connectPoint the egress connect point
272 - * @return boolean result of removal
273 - */
274 - public boolean removeEgressPoint(String connectPoint) {
275 - checkNotNull(connectPoint);
276 - return this.removeEgressPoint(ConnectPoint.deviceConnectPoint(connectPoint));
277 - }
278 -
279 - /**
280 - * Remove an egress from McastConnectPoint.
281 - *
282 - * @param cp the egress connect point
283 - * @return boolean result of removal
284 - */
285 - public boolean removeEgressPoint(ConnectPoint cp) {
286 - boolean removed = false;
287 - McastConnectPoint mcp = this.findEgressConnectPoint(checkNotNull(cp));
288 - if (mcp != null) {
289 - removed = egressPoints.remove(mcp);
290 - setDirty(true);
291 - }
292 - return removed;
293 - }
294 -
295 - /**
296 - * Add an egress McastConnectPoint.
297 - *
298 - * @param cpstr deviceId/port of the connect point
299 - */
300 - public McastConnectPoint addEgressPoint(String cpstr, McastConnectPoint.JoinSource interest) {
301 - checkNotNull(cpstr);
302 - checkNotNull(interest);
303 - return this.addEgressPoint(ConnectPoint.deviceConnectPoint(cpstr), interest);
304 - }
305 -
306 - /**
307 - * Get egress connect points for the route.
308 - *
309 - * @return Set of egress connect points
310 - */
311 - public Set<McastConnectPoint> getEgressPoints() {
312 - return egressPoints;
313 - }
314 -
315 - /**
316 - * Get egress McastConnectPoints points as ConnectPoints for intent system.
317 - *
318 - * @return Set of egress ConnectPoints
319 - */
320 - public Set<ConnectPoint> getEgressConnectPoints() {
321 - Set<ConnectPoint> cps = new HashSet<ConnectPoint>();
322 -
323 - for (McastConnectPoint mcp : egressPoints) {
324 - cps.add(mcp.getConnectPoint());
325 - }
326 - return cps;
327 - }
328 -
329 - /**
330 - * Find the Multicast Connect Point that contains the ConnectPoint.
331 - *
332 - * @param cp the regular ConnectPoint to match
333 - * @return the McastConnectPoint that contains cp or null if not found.
334 - */
335 - public McastConnectPoint findEgressConnectPoint(ConnectPoint cp) {
336 - for (McastConnectPoint mcp : this.egressPoints) {
337 - if (mcp.getConnectPoint().equals(cp)) {
338 - return mcp;
339 - }
340 - }
341 - return null;
342 - }
343 -
344 - /**
345 - * Remove specified interest from the given ConnectPoint.
346 - *
347 - * @param mcp connect point.
348 - * @param interest the protocol interested in this multicast stream
349 - * @return true if removed, false otherwise
350 - */
351 - public boolean removeInterest(McastConnectPoint mcp, McastConnectPoint.JoinSource interest) {
352 - checkNotNull(mcp);
353 - if (mcp.interest.contains(interest)) {
354 - mcp.interest.remove(interest);
355 - setDirty(true);
356 - return true;
357 - }
358 - return false;
359 - }
360 -
361 - /**
362 - * Get the number of times the packet has been punted.
363 - *
364 - * @return the punt count
365 - */
366 - @Override
367 - public int getPuntCount() {
368 - return puntCount;
369 - }
370 -
371 - /**
372 - * Increment the punt count.
373 - *
374 - * TODO: we need to handle wrapping.
375 - */
376 - @Override
377 - public void incrementPuntCount() {
378 - puntCount++;
379 - }
380 -
381 - /**
382 - * Have the McastIntentManager create and set the intent, then save the intent key.
383 - *
384 - * If we already have an intent, we will first withdraw the existing intent and
385 - * replace it with a new one. This will support the case where the ingress connectPoint
386 - * or group of egress connectPoints change.
387 - */
388 - @Override
389 - public void setIntent() {
390 - if (this.intentKey != null) {
391 - this.withdrawIntent();
392 - }
393 - McastIntentManager im = McastIntentManager.getInstance();
394 - SinglePointToMultiPointIntent intent = im.setIntent(this);
395 - this.intentKey = intent.key();
396 - }
397 -
398 - /**
399 - * Set the Intent key.
400 - *
401 - * @param intent the multicast intent
402 - */
403 - @Override
404 - public void setIntent(SinglePointToMultiPointIntent intent) {
405 - intentKey = intent.key();
406 - }
407 -
408 - /**
409 - * Get the intent key represented by this route.
410 - *
411 - * @return intentKey
412 - */
413 - @Override
414 - public Key getIntentKey() {
415 - return this.intentKey;
416 - }
417 -
418 -
419 - /**
420 - * Withdraw the intent and set the key to null.
421 - */
422 - @Override
423 - public void withdrawIntent() {
424 - if (intentKey == null) {
425 - // nothing to withdraw
426 - return;
427 - }
428 - McastIntentManager im = McastIntentManager.getInstance();
429 - im.withdrawIntent(this);
430 - this.intentKey = null;
431 - }
432 -
433 - /**
434 - * Pretty Print this Multicast Route. Works for McastRouteSource and McastRouteGroup.
435 - *
436 - * @return pretty string of the multicast route
437 - */
438 - @Override
439 - public String toString() {
440 - String out = String.format("(%s, %s)\n\t",
441 - saddr.toString(), gaddr.toString());
442 -
443 - out += "intent: ";
444 - out += (intentKey == null) ? "not installed" : this.intentKey.toString();
445 - out += "\n\tingress: ";
446 - out += (ingressPoint == null) ? "NULL" : ingressPoint.getConnectPoint().toString();
447 - out += "\n\tegress: {\n";
448 - if (egressPoints != null && !egressPoints.isEmpty()) {
449 - for (McastConnectPoint eg : egressPoints) {
450 - out += "\t\t" + eg.getConnectPoint().toString() + "\n";
451 - }
452 - }
453 - out += ("\t}\n");
454 - out += ("\tpunted: " + this.getPuntCount() + "\n");
455 - return out;
456 - }
457 -}
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 static com.google.common.base.Preconditions.checkNotNull;
19 -import java.util.HashMap;
20 -import org.onlab.packet.IpPrefix;
21 -
22 -/**
23 - * The McastRouteGroup extends the McastRouteBase class and serves two purposes:
24 - * first it represents a (*, G) multicast route entry. Second it serves
25 - * as a container for all (S, G) multicast route entries that belong
26 - * to the same group address.
27 - */
28 -public class McastRouteGroup extends McastRouteBase {
29 - private HashMap<IpPrefix, McastRouteSource> sources;
30 -
31 - /**
32 - * Class constructor.
33 - *
34 - * @param gaddr - String representation of group address.
35 - */
36 - public McastRouteGroup(String gaddr) {
37 - super(checkNotNull(gaddr));
38 - this.init();
39 - }
40 -
41 - /**
42 - * Create a multicast group.
43 - *
44 - * @param gpfx - Group address
45 - */
46 - public McastRouteGroup(IpPrefix gpfx) {
47 - super(checkNotNull(gpfx));
48 - this.init();
49 - }
50 -
51 - /**
52 - * Common initialization used by constructors.
53 - */
54 - private void init() {
55 - this.sources = new HashMap();
56 - super.isGroup = true;
57 - }
58 -
59 - /**
60 - * Find a specific multicast source address for this group.
61 - *
62 - * @param saddr the source address
63 - * @return the multicast source route or null if it does not exist
64 - */
65 - public McastRouteSource findSource(IpPrefix saddr) {
66 - return this.sources.get(checkNotNull(saddr));
67 - }
68 -
69 - /**
70 - * Return the entire set of multicast sources for this group.
71 - *
72 - * @return the set of multicast sources
73 - */
74 - public HashMap<IpPrefix, McastRouteSource> getSources() {
75 - return this.sources;
76 - }
77 -
78 - /**
79 - * Add a new McastRouteSource to this group.
80 - *
81 - * @param src the multicast source
82 - */
83 - public void addSource(McastRouteSource src) {
84 - checkNotNull(src);
85 - this.sources.put(src.getSaddr(), src);
86 - }
87 -
88 - /**
89 - * Remove the source with this specific IpPrefix from this group entry.
90 - *
91 - * @param spfx IP Prefix of the source to be removed
92 - * @return the source route that was just removed
93 - */
94 - public McastRouteSource removeSource(IpPrefix spfx) {
95 - McastRouteSource src = this.sources.remove(spfx);
96 - src.withdrawIntent();
97 - return src;
98 - }
99 -
100 - /**
101 - * Remove all sources from this.
102 - */
103 - public void removeSources() {
104 - for (McastRouteSource src : this.sources.values()) {
105 - src.withdrawIntent();
106 - this.sources.remove(src.getSaddr());
107 - }
108 - }
109 -
110 -}
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 static com.google.common.base.Preconditions.checkNotNull;
19 -import org.onlab.packet.IpPrefix;
20 -
21 -/**
22 - * This class represents and specific multicast senders source address. Objects from
23 - * this class will belong to the sources collection of the multicast group.
24 - */
25 -public class McastRouteSource extends McastRouteBase {
26 -
27 - // A reference to our parent group
28 - private McastRouteGroup group;
29 -
30 - /**
31 - * Create a multicast source with IpPrefixes.
32 - *
33 - * @param source the source address
34 - * @param group the group address
35 - */
36 - public McastRouteSource(IpPrefix source, IpPrefix group) {
37 - super(checkNotNull(source), checkNotNull(group));
38 - }
39 -
40 - /**
41 - * Set our parent multicast group.
42 - *
43 - * @param group the group this source belongs to
44 - */
45 - public void setGroup(McastRouteGroup group) {
46 - this.group = group;
47 - }
48 -}
...\ No newline at end of file ...\ No newline at end of file
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.apache.felix.scr.annotations.Service;
19 -import org.onlab.packet.IpPrefix;
20 -
21 -import java.util.Map;
22 -import java.util.concurrent.ConcurrentHashMap;
23 -import static com.google.common.base.Preconditions.checkNotNull;
24 -
25 -/**
26 - * The Mcast Route Table holds all multicast state for the controller.
27 - *
28 - * State for IPv4 and IPv6 are maintained. The tables are sets of McastRouteGroup
29 - * structures that represent (*, G) state with a series of egress ConnectPoints.
30 - * Each (*, G) may also have a set of (S, G) that may have there own set of
31 - * ingress and egress ConnectPoints.
32 - *
33 - * TODO: perhaps should probably create two separate singleton for IPv4 and IPv6 respectively.
34 - */
35 -@Service(value = org.onosproject.mfwd.impl.McastRouteTable.class)
36 -public final class McastRouteTable {
37 -
38 - /*
39 - * Create a map of the McastGroups indexed by the multicast group prefix.
40 - * We may choose to change the map data structure in to some form a radix trie
41 - * depending on the type of real world usage we see.
42 - */
43 - private final Map<IpPrefix, McastRouteGroup> mrib4;
44 - private final Map<IpPrefix, McastRouteGroup> mrib6;
45 - private static McastRouteTable instance = null;
46 -
47 - private Boolean ipv6Enabled = false;
48 -
49 - /**
50 - * Create the two v4 & v6 tables.
51 - */
52 - private McastRouteTable() {
53 - mrib4 = new ConcurrentHashMap<IpPrefix, McastRouteGroup>();
54 - if (ipv6Enabled) {
55 - mrib6 = new ConcurrentHashMap<IpPrefix, McastRouteGroup>();
56 - } else {
57 - mrib6 = null;
58 - }
59 - }
60 -
61 - /**
62 - * Get the single instance of this multicast group address.
63 - *
64 - * @return the multicast route table
65 - */
66 - public static McastRouteTable getInstance() {
67 - if (instance == null) {
68 - instance = new McastRouteTable();
69 - }
70 - return instance;
71 - }
72 -
73 - /**
74 - * Get the IPv4 MRIB.
75 - *
76 - * @return the IPv4 MRIB
77 - */
78 - public Map<IpPrefix, McastRouteGroup> getMrib4() {
79 - return mrib4;
80 - }
81 -
82 - /**
83 - * Get the IPv6 MRIB.
84 - *
85 - * @return Return the set of prefix keyed McastGroups
86 - */
87 - public Map<IpPrefix, McastRouteGroup> getMrib6() {
88 - return mrib6;
89 - }
90 -
91 - /**
92 - * Save the McastRouteGroup in the address family appropriate mrib.
93 - *
94 - * @param group The McastRouteGroup to save
95 - */
96 - private void storeGroup(McastRouteGroup group) {
97 - if (group.isIp4()) {
98 - mrib4.put(group.getGaddr(), group);
99 - } else if (group.isIp6() && ipv6Enabled) {
100 - mrib6.put(group.getGaddr(), group);
101 - }
102 - }
103 -
104 - /**
105 - * Remove the group.
106 - *
107 - * @param group the group to be removed
108 - */
109 - private void removeGroup(McastRouteGroup group) {
110 - IpPrefix gpfx = group.getGaddr();
111 - if (gpfx.isIp4()) {
112 - mrib4.remove(gpfx);
113 - } else if (gpfx.isIp6() && ipv6Enabled) {
114 - mrib6.remove(gpfx);
115 - }
116 - }
117 -
118 - /**
119 - * Add a multicast route to the MRIB. This function will.
120 - *
121 - * @param saddr source address * or x.x.x.x or x.x.x.x/y
122 - * @param gaddr group address x.x.x.x or x.x.x.x/y
123 - * @return the multicast route
124 - */
125 - public McastRouteBase addRoute(String saddr, String gaddr) {
126 - IpPrefix gpfx = IpPrefix.valueOf(gaddr);
127 - IpPrefix spfx = IpPrefix.valueOf(0, 0);
128 - if (saddr != null && !saddr.equals("*")) {
129 - spfx = IpPrefix.valueOf(saddr);
130 - }
131 - return addRoute(spfx, gpfx);
132 - }
133 -
134 - /**
135 - * Add a multicast route to the MRIB. This function will store either
136 - * (S, G) or (*, G) in the mrib if an entry does not already exist. If
137 - * an entry does exist it is returned to the caller.
138 - *
139 - * Every (S, G) is stored as part of it's parent group entry which also represents
140 - * (*, G) routes. In the case of a (S, G) we will also create the (*, G) entry if needed
141 - * then save the (S, G) to the (*, G).
142 - *
143 - * @param spfx the source prefix
144 - * @param gpfx the group prefix
145 - * @return the resulting McastRouteSource or McastRouteGroup accordingly.
146 - */
147 - public McastRouteBase addRoute(IpPrefix spfx, IpPrefix gpfx) {
148 -
149 - /**
150 - * If a group route (*, g) does not exist we will need to make so we
151 - * can start attaching our sources to the group entry.
152 - */
153 - McastRouteGroup group = findMcastGroup(gpfx);
154 - if (group == null) {
155 - group = new McastRouteGroup(gpfx);
156 -
157 - // Save it for later
158 - if (gpfx.isIp4()) {
159 - this.mrib4.put(gpfx, group);
160 - } else if (gpfx.isIp6() && ipv6Enabled) {
161 - this.mrib6.put(gpfx, group);
162 - }
163 - }
164 -
165 - /**
166 - * If the source prefix length is 0 then we have our (*, g) entry, we can
167 - * just return now.
168 - */
169 - if (spfx.prefixLength() == 0) {
170 - return group;
171 - }
172 -
173 - // See if the source already exists. If so just return it.
174 - McastRouteSource source = group.findSource(spfx);
175 - if (source != null) {
176 - return source;
177 - }
178 -
179 - /**
180 - * We have the group but no source. We need to create the source then add it
181 - * to the group.
182 - */
183 - source = new McastRouteSource(spfx, gpfx);
184 -
185 - // Have the source save it's parent
186 - source.setGroup(group);
187 -
188 - // Save this source as part of this group
189 - group.addSource(source);
190 -
191 - return source;
192 - }
193 -
194 - /**
195 - * Delete a specific egress from the MRIB.
196 - *
197 - * @param saddr source address * or x.x.x.x or x.x.x.x/y
198 - * @param gaddr group address x.x.x.x or x.x.x.x/y
199 - * @param egress group address x.x.x.x or x.x.x.x/y
200 - * @return boolean if egress was deleted
201 - */
202 - public boolean removeEgress(String saddr, String gaddr, String egress) {
203 -
204 - IpPrefix gpfx = IpPrefix.valueOf(gaddr);
205 - IpPrefix spfx = IpPrefix.valueOf(0, 0);
206 - if (saddr != null && !saddr.equals("*")) {
207 - spfx = IpPrefix.valueOf(saddr);
208 - }
209 -
210 - McastRouteSource src = (McastRouteSource) findBestMatch(spfx, gpfx);
211 - boolean removed = src.removeEgressPoint(egress);
212 - if (removed) {
213 - src.setIntent();
214 - }
215 - return removed;
216 - }
217 -
218 - /**
219 - * Delete a multicast route from the MRIB.
220 - *
221 - * @param saddr source address * or x.x.x.x or x.x.x.x/y
222 - * @param gaddr group address x.x.x.x or x.x.x.x/y
223 - */
224 - public void removeRoute(String saddr, String gaddr) {
225 - IpPrefix gpfx = IpPrefix.valueOf(gaddr);
226 - IpPrefix spfx = IpPrefix.valueOf(0, 0);
227 - if (saddr != null && !saddr.equals("*")) {
228 - spfx = IpPrefix.valueOf(saddr);
229 - }
230 - removeRoute(spfx, gpfx);
231 - }
232 -
233 - /**
234 - * Remove a multicast route.
235 - *
236 - * @param spfx the source prefix
237 - * @param gpfx the group prefix
238 - */
239 - public void removeRoute(IpPrefix spfx, IpPrefix gpfx) {
240 -
241 - /**
242 - * If a group route (*, g) does not exist we will need to make so we
243 - * can start attaching our sources to the group entry.
244 - */
245 - McastRouteGroup group = findMcastGroup(gpfx);
246 - if (group == null) {
247 - // The group does not exist, we can't remove it.
248 - return;
249 - }
250 -
251 - /**
252 - * If the source prefix length is 0 then we have a (*, g) entry, which
253 - * means we will remove this group and all of it's sources. We will
254 - * also withdraw it's intent if need be.
255 - */
256 - if (spfx.prefixLength() > 0) {
257 - group.removeSource(spfx);
258 -
259 - /*
260 - * Now a little house keeping. If this group has no more sources
261 - * nor egress connectPoints git rid of it.
262 - */
263 - if (group.getSources().size() == 0 &&
264 - group.getEgressPoints().size() == 0) {
265 - removeGroup(group);
266 - }
267 -
268 - } else {
269 - // Group remove has been explicitly requested.
270 - group.removeSources();
271 - group.withdrawIntent();
272 - removeGroup(group);
273 - }
274 - }
275 -
276 - /**
277 - * Find the specific multicast group entry.
278 - *
279 - * @param group the group address
280 - * @return McastRouteGroup the multicast (*, G) group route
281 - */
282 - public McastRouteGroup findMcastGroup(IpPrefix group) {
283 - McastRouteGroup g = null;
284 - if (group.isIp4()) {
285 - g = mrib4.get(group);
286 - } else if (group.isIp6() && ipv6Enabled) {
287 - g = mrib6.get(group);
288 - }
289 - return g;
290 - }
291 -
292 - /**
293 - * Find the multicast (S, G) entry if it exists.
294 - *
295 - * @param saddr the source address
296 - * @param gaddr the group address
297 - * @return The multicast source route entry if it exists, null if it does not.
298 - */
299 - public McastRouteSource findMcastSource(IpPrefix saddr, IpPrefix gaddr) {
300 - McastRouteGroup grp = findMcastGroup(checkNotNull(gaddr));
301 - if (grp == null) {
302 - return null;
303 - }
304 - return grp.findSource(saddr);
305 - }
306 -
307 - /**
308 - * This will first look up a Group entry. If no group entry was found null will
309 - * be returned. If the group entry has been found we will then look up the (s, g) entry.
310 - * If the (s, g) entry has been found, that will be returned. If no (s, g) was found
311 - * the (*, g) group entry will be returned.
312 - *
313 - * @param saddr the source address
314 - * @param gaddr the group address
315 - * @return return the best matching McastRouteSource or McastRouteGroup
316 - */
317 - public McastRoute findBestMatch(IpPrefix saddr, IpPrefix gaddr) {
318 - McastRouteGroup grp = this.findMcastGroup(checkNotNull(gaddr));
319 - if (grp == null) {
320 - return null;
321 - }
322 -
323 - // Found a group now look for a source
324 - McastRouteSource src = grp.findSource(checkNotNull(saddr));
325 - if (src == null) {
326 - return grp;
327 - }
328 -
329 - return src;
330 - }
331 -
332 - /**
333 - * Print out the multicast route table in it's entirety.
334 - *
335 - * TODO: Eventually we will have to implement paging and how to handle large tables.
336 - * @return String
337 - */
338 - public String printMcastRouteTable() {
339 - String out = this.toString() + "\n";
340 -
341 - for (McastRouteGroup grp : mrib4.values()) {
342 - out += grp.toString() + "\n";
343 - for (McastRouteSource src : grp.getSources().values()) {
344 - out += src.toString() + "\n";
345 - }
346 - }
347 - return out;
348 - }
349 -
350 - /**
351 - * Print out a summary of groups in the MRIB.
352 - *
353 - * @return String
354 - */
355 - public String toString() {
356 - String out = "Mcast Route Table: ";
357 - out += mrib4.size() + " IPv4 Multicast Groups\n";
358 - if (ipv6Enabled) {
359 - out += mrib6.size() + " IPv6 Multicast Groups\n";
360 - }
361 - return out;
362 - }
363 -}
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.rest;
17 -
18 -import java.io.IOException;
19 -import com.fasterxml.jackson.databind.ObjectMapper;
20 -import com.fasterxml.jackson.databind.node.ObjectNode;
21 -
22 -import javax.ws.rs.DefaultValue;
23 -import javax.ws.rs.QueryParam;
24 -import javax.ws.rs.Consumes;
25 -import javax.ws.rs.GET;
26 -import javax.ws.rs.POST;
27 -import javax.ws.rs.DELETE;
28 -import javax.ws.rs.Path;
29 -import javax.ws.rs.Produces;
30 -import javax.ws.rs.core.MediaType;
31 -import javax.ws.rs.core.Response;
32 -
33 -import org.onosproject.mfwd.impl.McastConnectPoint;
34 -import org.onosproject.mfwd.impl.McastRouteTable;
35 -import org.onosproject.mfwd.impl.McastRouteBase;
36 -import org.onosproject.mfwd.impl.MRibCodec;
37 -import org.onosproject.rest.AbstractWebResource;
38 -
39 -import org.slf4j.Logger;
40 -import static org.slf4j.LoggerFactory.getLogger;
41 -
42 -/**
43 - * Rest API for Multicast Forwarding.
44 - */
45 -@Path("mcast")
46 -public class McastResource extends AbstractWebResource {
47 -
48 - private final Logger log = getLogger(getClass());
49 - private static final String SOURCE_ADDRESS = "sourceAddress";
50 - private static final String GROUP_ADDRESS = "groupAddress";
51 - private static final String INGRESS_POINT = "ingressPoint";
52 - private static final String EGRESS_POINT = "egressPoint";
53 - private static final String MCAST_GROUP = "mcastGroup";
54 -
55 - /**
56 - * Retrieve the multicast route table.
57 - *
58 - * @return the multicast route table.
59 - * @throws IOException if an error occurs
60 - */
61 - @Path("show")
62 - @GET
63 - @Produces(MediaType.APPLICATION_JSON)
64 - public Response showAll() throws IOException {
65 - McastRouteTable mrt = McastRouteTable.getInstance();
66 - ObjectNode pushContent = new MRibCodec().encode(mrt , this);
67 - return ok(pushContent.toString()).build();
68 - }
69 -
70 - /**
71 - * Static join a multicast flow.
72 - *
73 - * @param sAddr source address to join
74 - * @param gAddr group address to join
75 - * @param ports ingress and egress ConnectPoints to join
76 - * @return the Result of the join
77 - * @throws IOException if something failed with the join command
78 - */
79 - @Path("/join")
80 - @POST
81 - @Consumes(MediaType.APPLICATION_JSON)
82 - @Produces(MediaType.TEXT_PLAIN)
83 - public Response join(@QueryParam("src") String sAddr,
84 - @QueryParam("grp") String gAddr,
85 - @DefaultValue("") @QueryParam("ports") String ports)
86 - throws IOException {
87 -
88 - ObjectMapper mapper = new ObjectMapper();
89 - log.debug("Source IP Address: " + sAddr);
90 - log.debug("Destination IP Address: " + gAddr);
91 - log.debug("Ingress and Egress ports: " + ports);
92 -
93 - String output = "Insertion Faild";
94 - if (sAddr != null && gAddr != null && ports != null) {
95 -
96 - String[] portArr = ports.split(",");
97 - log.debug("Port Array Length: " + portArr.length);
98 - McastRouteTable mrt = McastRouteTable.getInstance();
99 - McastRouteBase mr = mrt.addRoute(sAddr, gAddr);
100 -
101 - // Port format "of:0000000000000023/4"
102 - log.debug("checking inside outer if: " + portArr.length);
103 -
104 - if (mr != null && portArr != null && portArr.length > 0) {
105 -
106 - String inCP = portArr[0];
107 - log.debug("Ingress port provided: " + inCP);
108 - mr.addIngressPoint(inCP);
109 -
110 - for (int i = 1; i < portArr.length; i++) {
111 - String egCP = portArr[i];
112 - log.debug("Egress port provided: " + egCP);
113 - mr.addEgressPoint(egCP, McastConnectPoint.JoinSource.STATIC);
114 - }
115 - mrt.printMcastRouteTable();
116 - output = "Successfully Inserted";
117 - }
118 - } else {
119 - output = "Please Insert the rest uri correctly";
120 - }
121 - return Response.ok(output).build();
122 - }
123 -
124 - /**
125 - * Delete multicast state.
126 - *
127 - * @param src address to be deleted
128 - * @param grp address to be deleted
129 - * @return status of delete if successful
130 - */
131 - @Path("/delete")
132 - @DELETE
133 - @Consumes(MediaType.TEXT_PLAIN)
134 - @Produces(MediaType.TEXT_PLAIN)
135 - public Response removeMcastFlow(@QueryParam("src") String src,
136 - @QueryParam("grp") String grp) {
137 -
138 - String resp = "Failed to delete";
139 - log.info("Source IP Address to delete: " + src);
140 - log.info("Destination IP Address to delete: " + grp);
141 - McastRouteTable mrt = McastRouteTable.getInstance();
142 - if (src != null && grp != null) {
143 - mrt.removeRoute(src, grp);
144 - resp = "Deleted flow for src " + src + " and grp " + grp;
145 - }
146 -
147 - return Response.ok(resp).build();
148 - }
149 -}
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 -/**
18 - * REST API for multicase forwarding.
19 - */
20 -package org.onosproject.mfwd.rest;