Charles Chan
Committed by Gerrit Code Review

Remove duplicated multicast prefix declaration

(Following #7957)
Also,
Update copyright
Few documentation improvements

Change-Id: If4a6b9f168e9d7587976f1f2b59c2b59b81c6c2f
/*
* 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.
......@@ -97,11 +97,10 @@ public class IgmpSnoop {
private static final int DEFAULT_QUERY_PERIOD_SECS = 60;
private static final byte DEFAULT_IGMP_RESP_CODE = 100;
private static final String DEFAULT_MCAST_ADDR = "224.0.0.0/4";
@Property(name = "multicastAddress",
label = "Define the multicast base range to listen to")
private String multicastAddress = DEFAULT_MCAST_ADDR;
private String multicastAddress = IpPrefix.IPV4_MULTICAST_PREFIX.toString();
@Property(name = "queryPeriod", intValue = DEFAULT_QUERY_PERIOD_SECS,
label = "Delay in seconds between successive query runs")
......@@ -243,6 +242,7 @@ public class IgmpSnoop {
protected void modified(ComponentContext context) {
Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
// TODO read multicastAddress from config
String strQueryPeriod = Tools.get(properties, "queryPeriod");
String strResponseCode = Tools.get(properties, "maxRespCode");
try {
......@@ -419,11 +419,11 @@ public class IgmpSnoop {
if (ip.getProtocol() != IPv4.PROTOCOL_IGMP ||
!IpPrefix.IPV4_MULTICAST_RANGE.contains(gaddr)) {
!IpPrefix.IPV4_MULTICAST_PREFIX.contains(gaddr)) {
return;
}
if (IpPrefix.IPV4_MULTICAST_RANGE.contains(saddr)) {
if (IpPrefix.IPV4_MULTICAST_PREFIX.contains(saddr)) {
log.debug("IGMP Picked up a packet with a multicast source address.");
return;
}
......
/*
* 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.
......@@ -67,7 +67,6 @@ import static org.slf4j.LoggerFactory.getLogger;
public class McastForwarding {
private final Logger log = getLogger(getClass());
private final IpPrefix mcast = IpPrefix.valueOf("224.0.0.0/4");
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
......@@ -101,7 +100,7 @@ public class McastForwarding {
// Build a traffic selector for all multicast traffic
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(mcast);
selector.matchIPDst(IpPrefix.IPV4_MULTICAST_PREFIX);
packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId);
......
/*
* 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.
......@@ -25,7 +25,6 @@ import org.apache.commons.lang3.tuple.Pair;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.packet.EthType;
import org.onlab.packet.IPv4;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.VlanId;
import org.onlab.util.KryoNamespace;
import org.onosproject.core.ApplicationId;
......@@ -102,7 +101,8 @@ public class OltPipeline extends AbstractHandlerBehaviour implements Pipeliner {
private DeviceId deviceId;
private ApplicationId appId;
private IpPrefix mcastPrefix = IpPrefix.valueOf("224.0.0.0/4");
// NOTE: OLT currently has some issue with cookie 0. Pick something larger
// to avoid collision
private AtomicLong counter = new AtomicLong(123);
protected FlowObjectiveStore flowObjectiveStore;
......@@ -348,7 +348,7 @@ public class OltPipeline extends AbstractHandlerBehaviour implements Pipeliner {
return false;
}
return mcastPrefix.contains(ip.ip());
return ip.ip().isMulticast();
}
......
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2014-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.
......@@ -321,8 +321,8 @@ public class IpAddress implements Comparable<IpAddress> {
*/
public boolean isMulticast() {
return isIp4() ?
Ip4Prefix.IPV4_MULTICAST_RANGE.contains(this.getIp4Address()) :
Ip6Prefix.IPV6_MULTICAST_RANGE.contains(this.getIp6Address());
Ip4Prefix.IPV4_MULTICAST_PREFIX.contains(this.getIp4Address()) :
Ip6Prefix.IPV6_MULTICAST_PREFIX.contains(this.getIp6Address());
}
@Override
......
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2014-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.
......@@ -43,11 +43,11 @@ public class IpPrefix {
/**
* An IpPrefix that contains all IPv4 multicast addresses.
*/
public static final IpPrefix IPV4_MULTICAST_RANGE = IpPrefix.valueOf("224.0.0.0/4");
public static final IpPrefix IPV4_MULTICAST_PREFIX = IpPrefix.valueOf("224.0.0.0/4");
/**
* An IpPrefix that contains all IPv6 multicast addresses.
*/
public static final IpPrefix IPV6_MULTICAST_RANGE = IpPrefix.valueOf("ff00::/8");
public static final IpPrefix IPV6_MULTICAST_PREFIX = IpPrefix.valueOf("ff00::/8");
private final IpAddress address;
private final short prefixLength;
......@@ -93,6 +93,17 @@ public class IpPrefix {
}
/**
* Check if this IP prefix is a multicast prefix.
*
* @return true if this prefix a multicast prefix
*/
public boolean isMulticast() {
return isIp4() ?
IPV4_MULTICAST_PREFIX.contains(this.getIp4Prefix()) :
IPV6_MULTICAST_PREFIX.contains(this.getIp6Prefix());
}
/**
* Returns the IP address value of the prefix.
*
* @return the IP address value of the prefix
......
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2014-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.
......
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2014-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.
......@@ -97,6 +97,25 @@ public class IpPrefixTest {
}
/**
* Tests if the prefix is a multicast prefix.
*/
@Test
public void testIsMulticast() {
IpPrefix v4Unicast = IpPrefix.valueOf("10.0.0.1/16");
IpPrefix v4Multicast = IpPrefix.valueOf("224.0.0.1/4");
IpPrefix v4Overlap = IpPrefix.valueOf("192.0.0.0/2");
IpPrefix v6Unicast = IpPrefix.valueOf("1000::1/8");
IpPrefix v6Multicast = IpPrefix.valueOf("ff02::1/8");
IpPrefix v6Overlap = IpPrefix.valueOf("ff00::1/4");
assertFalse(v4Unicast.isMulticast());
assertTrue(v4Multicast.isMulticast());
assertFalse(v4Overlap.isMulticast());
assertFalse(v6Unicast.isMulticast());
assertTrue(v6Multicast.isMulticast());
assertFalse(v6Overlap.isMulticast());
}
/**
* Tests returning the IP address value and IP address prefix length of
* an IPv4 prefix.
*/
......