Committed by
Gerrit Code Review
Refactored Mfwd to use new mcastroutemanager
Change-Id: I7aca7f118221ed505aeb7fcace0ef9dccb468a34
Showing
15 changed files
with
90 additions
and
1060 deletions
... | @@ -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 |
This diff is collapsed. Click to expand it.
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 |
This diff is collapsed. Click to expand it.
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; |
-
Please register or login to post a comment