summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/mfwd/src/main/java/org/onosproject/mfwd/impl/McastIntentManager.java
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-10-09 18:32:44 -0700
committerAshlee Young <ashlee@onosfw.com>2015-10-09 18:32:44 -0700
commit6a07d2d622eaa06953f3353e39c080984076e8de (patch)
treebfb50a2090fce186c2cc545a400c969bf2ea702b /framework/src/onos/apps/mfwd/src/main/java/org/onosproject/mfwd/impl/McastIntentManager.java
parente6d71622143ff9b2421a1abbe8434b954b5b1099 (diff)
Updated master to commit id 6ee8aa3e67ce89908a8c93aa9445c6f71a18f986
Change-Id: I94b055ee2f298daf71e2ec794fd0f2495bd8081f
Diffstat (limited to 'framework/src/onos/apps/mfwd/src/main/java/org/onosproject/mfwd/impl/McastIntentManager.java')
-rw-r--r--framework/src/onos/apps/mfwd/src/main/java/org/onosproject/mfwd/impl/McastIntentManager.java133
1 files changed, 133 insertions, 0 deletions
diff --git a/framework/src/onos/apps/mfwd/src/main/java/org/onosproject/mfwd/impl/McastIntentManager.java b/framework/src/onos/apps/mfwd/src/main/java/org/onosproject/mfwd/impl/McastIntentManager.java
new file mode 100644
index 00000000..90f65c94
--- /dev/null
+++ b/framework/src/onos/apps/mfwd/src/main/java/org/onosproject/mfwd/impl/McastIntentManager.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.mfwd.impl;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.Ethernet;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.SinglePointToMultiPointIntent;
+import org.onosproject.net.intent.IntentService;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+
+@Component(immediate = true)
+@Service(value = org.onosproject.mfwd.impl.McastIntentManager.class)
+public class McastIntentManager {
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected IntentService intentService;
+
+ private static McastIntentManager instance;
+
+ public McastIntentManager() {
+ instance = this;
+ }
+
+ /**
+ * Active this component.
+ */
+ @Activate
+ public void activate() { }
+
+ /**
+ * Deactivate this component.
+ */
+ @Deactivate
+ public void deactivate() {
+ withdrawAllIntents();
+ }
+
+ /**
+ * Get instance of this intentManager.
+ *
+ * @return the instance of this intent manager.
+ */
+ public static McastIntentManager getInstance() {
+ if (instance == null) {
+ instance = new McastIntentManager();
+ }
+ return instance;
+ }
+
+ /**
+ * Install the PointToMultipoint forwarding intent.
+ *
+ * @param mroute multicast route entry
+ * @return the intent that has been set or null otherwise
+ */
+ public SinglePointToMultiPointIntent setIntent(McastRoute mroute) {
+ TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
+ TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
+
+ if (mroute.getIngressPoint() == null ||
+ mroute.getEgressPoints().isEmpty()) {
+ return null;
+ }
+
+ /*
+ * Match the group AND source addresses. We will also check ether type to
+ * determine if we are doing ipv4 or ipv6.
+ *
+ * If we really wanted to be pendantic we could put in a
+ * condition to make sure the ethernet MAC address was also
+ * mcast.
+ */
+ selector.matchEthType(Ethernet.TYPE_IPV4)
+ .matchIPDst(mroute.getGaddr())
+ .matchIPSrc(mroute.getSaddr());
+
+ SinglePointToMultiPointIntent intent =
+ SinglePointToMultiPointIntent.builder()
+ .appId(McastForwarding.getAppId())
+ .selector(selector.build())
+ .treatment(treatment)
+ .ingressPoint(mroute.getIngressPoint().getConnectPoint())
+ .egressPoints(mroute.getEgressConnectPoints()).
+ build();
+
+ intentService.submit(intent);
+ return intent;
+ }
+
+ /**
+ * Withdraw the intent represented by this route.
+ *
+ * @param mroute the mcast route whose intent we want to remove
+ */
+ public void withdrawIntent(McastRouteBase mroute) {
+ Intent intent = intentService.getIntent(mroute.getIntentKey());
+ intentService.withdraw(intent);
+ }
+
+ /**
+ * Withdraw all intents.
+ *
+ * This will be called from the deactivate method so we don't leave
+ * a mess behind us after we leave.
+ */
+ public void withdrawAllIntents() {
+ for (Intent intent : intentService.getIntents()) {
+ intentService.withdraw(intent);
+ }
+ }
+}