Stop referencing the variable egressPorts if it is null.  Also
check that the source and group addresses are unicast and
multicast respectively before adding them to the MRIB.

Change-Id: Ice480f58776948b9371060f78b99eee5c0bb0993
diff --git a/mfwd/src/main/java/org/onosproject/mfwd/cli/McastJoinCommand.java b/mfwd/src/main/java/org/onosproject/mfwd/cli/McastJoinCommand.java
index 5c78cbd..5172691 100644
--- a/mfwd/src/main/java/org/onosproject/mfwd/cli/McastJoinCommand.java
+++ b/mfwd/src/main/java/org/onosproject/mfwd/cli/McastJoinCommand.java
@@ -17,6 +17,7 @@
 

 import org.apache.karaf.shell.commands.Argument;

 import org.apache.karaf.shell.commands.Command;

+import org.onlab.packet.IpPrefix;

 import org.onosproject.cli.AbstractShellCommand;

 

 import org.onosproject.mfwd.impl.McastRouteBase;

@@ -52,7 +53,24 @@
     @Override

     protected void execute() {

         McastRouteTable mrib = McastRouteTable.getInstance();

+        IpPrefix mcast = IpPrefix.valueOf("224.0.0.0/4");

+        IpPrefix saddr = IpPrefix.valueOf(sAddr);

+        if (mcast.contains(saddr)) {

+            print("Error: the source address " + sAddr + " must be an IPv4 unicast address");

+            return;

+        }

+

+        IpPrefix gaddr = IpPrefix.valueOf(gAddr);

+        if (!mcast.contains(gaddr)) {

+            print("Error: " + gAddr + " must be a multicast group address");

+            return;

+        }

+

         McastRouteBase mr = mrib.addRoute(sAddr, gAddr);

+        if (mr == null) {

+            print("Error: unable to save the multicast state");

+            return;

+        }

 

         // Port format "of:0000000000000023/4"

         if (ingressPort != null) {

@@ -60,6 +78,12 @@
             log.debug("Ingress port provided: " + inCP);

             String [] cp = inCP.split("/");

             mr.addIngressPoint(cp[0], Long.parseLong(cp[1]));

+        } else {

+            return;

+        }

+

+        if (ports == null) {

+            return;

         }

 

         for (int i = 0; i < ports.length; i++) {