Added some incoming JoinPrune processing
Change-Id: I7c89f05119ffa012b8e79f05d0f5f63744282ffb
diff --git a/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java b/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java
index 1bedd9d..30d08c8 100644
--- a/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java
+++ b/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2015, 2016 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.
@@ -19,10 +19,13 @@
import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.PIM;
import org.onlab.packet.pim.PIMHello;
import org.onlab.packet.pim.PIMHelloOption;
+import org.onlab.packet.pim.PIMJoinPrune;
+import org.onlab.packet.pim.PIMJoinPruneGroup;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
@@ -348,7 +351,39 @@
* @param ethPkt the Ethernet packet header.
*/
public void processJoinPrune(Ethernet ethPkt) {
- // TODO: add Join/Prune processing code.
+
+ IPv4 ip = (IPv4) ethPkt.getPayload();
+ checkNotNull(ip);
+
+ PIM pim = (PIM) ip.getPayload();
+ checkNotNull(pim);
+
+ PIMJoinPrune jpHdr = (PIMJoinPrune) pim.getPayload();
+ checkNotNull(jpHdr);
+
+ /*
+ * The Join/Prune messages are grouped by Group address. We'll walk each group address
+ * where we will possibly have to walk a list of source address for the joins and prunes.
+ */
+ Collection<PIMJoinPruneGroup> jpgs = jpHdr.getJoinPrunes();
+ for (PIMJoinPruneGroup jpg : jpgs) {
+ IpPrefix gpfx = jpg.getGroup();
+
+ // Walk the joins first.
+ for (IpPrefix spfx : jpg.getJoins().values()) {
+
+ // We may need
+
+
+ }
+
+ for (IpPrefix spfx : jpg.getPrunes().values()) {
+
+ // TODO: this is where we many need to remove multi-cast state and possibly intents.
+
+ }
+ }
+
}
/**
diff --git a/utils/misc/src/main/java/org/onlab/packet/pim/PIMJoinPrune.java b/utils/misc/src/main/java/org/onlab/packet/pim/PIMJoinPrune.java
index 45fe287..a307ad6 100644
--- a/utils/misc/src/main/java/org/onlab/packet/pim/PIMJoinPrune.java
+++ b/utils/misc/src/main/java/org/onlab/packet/pim/PIMJoinPrune.java
@@ -21,6 +21,7 @@
import org.onlab.packet.IpPrefix;
import java.nio.ByteBuffer;
+import java.util.Collection;
import java.util.HashMap;
import static com.google.common.base.MoreObjects.toStringHelper;
@@ -31,16 +32,7 @@
private PIMAddrUnicast upstreamAddr = new PIMAddrUnicast();
private short holdTime = (short) 0xffff;
- private class JoinPruneGroup {
- protected IpPrefix group;
- protected HashMap<IpPrefix, IpPrefix> joins = new HashMap<>();
- protected HashMap<IpPrefix, IpPrefix> prunes = new HashMap<>();
-
- public JoinPruneGroup(IpPrefix grp) {
- group = grp;
- }
- }
- private HashMap<IpPrefix, JoinPruneGroup> joinPrunes = new HashMap<>();
+ private HashMap<IpPrefix, PIMJoinPruneGroup> joinPrunes = new HashMap<>();
/**
* Get the J/P hold time.
@@ -79,6 +71,15 @@
}
/**
+ * Get the JoinPrune Group with all the joins and prunes.
+ *
+ * @return the joinPruneGroup collection
+ */
+ public Collection<PIMJoinPruneGroup> getJoinPrunes() {
+ return joinPrunes.values();
+ }
+
+ /**
* Add the specified s,g to join field.
*
* @param saddr the source address of the route
@@ -99,13 +100,13 @@
* @param join true for join, false for prune
*/
public void addJoinPrune(IpPrefix spfx, IpPrefix gpfx, boolean join) {
- JoinPruneGroup jpg = joinPrunes.get(gpfx);
+ PIMJoinPruneGroup jpg = joinPrunes.get(gpfx);
if (jpg == null) {
- jpg = new JoinPruneGroup(gpfx);
+ jpg = new PIMJoinPruneGroup(gpfx);
joinPrunes.put(gpfx, jpg);
}
- HashMap<IpPrefix, IpPrefix> members = (join) ? jpg.joins : jpg.prunes;
+ HashMap<IpPrefix, IpPrefix> members = (join) ? jpg.getJoins() : jpg.getPrunes();
if (members.get(spfx) == null) {
members.put(spfx, spfx);
}
@@ -151,22 +152,22 @@
bb.putShort(this.holdTime);
// Walk the group list and input all groups
- for (JoinPruneGroup jpg : joinPrunes.values()) {
- PIMAddrGroup grp = new PIMAddrGroup(jpg.group);
+ for (PIMJoinPruneGroup jpg : joinPrunes.values()) {
+ PIMAddrGroup grp = new PIMAddrGroup(jpg.getGroup());
bb.put(grp.serialize());
// put the number of joins and prunes
- bb.putShort((short) jpg.joins.size());
- bb.putShort((short) jpg.prunes.size());
+ bb.putShort((short) jpg.getJoins().size());
+ bb.putShort((short) jpg.getPrunes().size());
// Set all of the joins
- for (IpPrefix spfx : jpg.joins.values()) {
+ for (IpPrefix spfx : jpg.getJoins().values()) {
PIMAddrSource src = new PIMAddrSource(spfx);
bb.put(src.serialize());
}
// Set all of the prunes
- for (IpPrefix spfx : jpg.prunes.values()) {
+ for (IpPrefix spfx : jpg.getPrunes().values()) {
PIMAddrSource src = new PIMAddrSource(spfx);
bb.put(src.serialize());
}
diff --git a/utils/misc/src/main/java/org/onlab/packet/pim/PIMJoinPruneGroup.java b/utils/misc/src/main/java/org/onlab/packet/pim/PIMJoinPruneGroup.java
new file mode 100644
index 0000000..d4dab3e
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/packet/pim/PIMJoinPruneGroup.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 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.onlab.packet.pim;
+
+import org.onlab.packet.IpPrefix;
+
+import java.util.HashMap;
+
+public class PIMJoinPruneGroup {
+ private IpPrefix group;
+ private HashMap<IpPrefix, IpPrefix> joins = new HashMap<>();
+ private HashMap<IpPrefix, IpPrefix> prunes = new HashMap<>();
+
+ public PIMJoinPruneGroup(IpPrefix grp) {
+ group = grp;
+ }
+
+ public IpPrefix getGroup() {
+ return group;
+ }
+
+ public void setGroup(IpPrefix g) {
+ group = g;
+ }
+
+ public HashMap<IpPrefix, IpPrefix> getJoins() {
+ return joins;
+ }
+
+ public HashMap<IpPrefix, IpPrefix> getPrunes() {
+ return prunes;
+ }
+
+}