ONOS-3165. Make MAC not mandatory. Fixing IP (constructor was still doing checkNotNull)

Change-Id: I6663504f63df25260aa62c28337cdadb83dfd361
This commit is contained in:
Luca Prete 2015-10-16 11:19:53 +02:00 committed by Gerrit Code Review
parent 9ec239e2e8
commit e3879f7651
4 changed files with 17 additions and 14 deletions

View File

@ -43,7 +43,7 @@ public class InterfaceAddCommand extends AbstractShellCommand {
@Option(name = "-m", aliases = "--mac", @Option(name = "-m", aliases = "--mac",
description = "MAC address of the interface", description = "MAC address of the interface",
required = true, multiValued = false) required = false, multiValued = false)
private String mac = null; private String mac = null;
@Option(name = "-i", aliases = "--ip", @Option(name = "-i", aliases = "--ip",
@ -68,10 +68,12 @@ public class InterfaceAddCommand extends AbstractShellCommand {
} }
} }
MacAddress macAddr = mac == null ? null : MacAddress.valueOf(mac);
VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan)); VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan));
Interface intf = new Interface(ConnectPoint.deviceConnectPoint(connectPoint), Interface intf = new Interface(ConnectPoint.deviceConnectPoint(connectPoint),
ipAddresses, MacAddress.valueOf(mac), vlanId); ipAddresses, macAddr, vlanId);
interfaceService.add(intf); interfaceService.add(intf);
} }

View File

@ -39,7 +39,6 @@ public class InterfaceConfig extends Config<ConnectPoint> {
public static final String MAC = "mac"; public static final String MAC = "mac";
public static final String VLAN = "vlan"; public static final String VLAN = "vlan";
public static final String MAC_MISSING_ERROR = "Must have a MAC address for each interface";
public static final String CONFIG_VALUE_ERROR = "Error parsing config value"; public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
/** /**
@ -55,15 +54,12 @@ public class InterfaceConfig extends Config<ConnectPoint> {
for (JsonNode intfNode : array) { for (JsonNode intfNode : array) {
Set<InterfaceIpAddress> ips = getIps(intfNode); Set<InterfaceIpAddress> ips = getIps(intfNode);
if (intfNode.path(MAC).isMissingNode()) { String mac = intfNode.path(MAC).asText();
throw new ConfigException(MAC_MISSING_ERROR); MacAddress macAddr = mac.isEmpty() ? null : MacAddress.valueOf(mac);
}
MacAddress mac = MacAddress.valueOf(intfNode.path(MAC).asText());
VlanId vlan = getVlan(intfNode); VlanId vlan = getVlan(intfNode);
interfaces.add(new Interface(subject, ips, mac, vlan)); interfaces.add(new Interface(subject, ips, macAddr, vlan));
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new ConfigException(CONFIG_VALUE_ERROR, e); throw new ConfigException(CONFIG_VALUE_ERROR, e);
@ -79,7 +75,10 @@ public class InterfaceConfig extends Config<ConnectPoint> {
*/ */
public void addInterface(Interface intf) { public void addInterface(Interface intf) {
ObjectNode intfNode = array.addObject(); ObjectNode intfNode = array.addObject();
intfNode.put(MAC, intf.mac().toString());
if (intf.mac() != null) {
intfNode.put(MAC, intf.mac().toString());
}
if (!intf.ipAddresses().isEmpty()) { if (!intf.ipAddresses().isEmpty()) {
intfNode.set(IPS, putIps(intf.ipAddresses())); intfNode.set(IPS, putIps(intf.ipAddresses()));

View File

@ -30,7 +30,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* An Interface maps network configuration information (such as addresses and * An Interface maps network configuration information (such as addresses and
* vlans) to a port in the network. * vlans) to a port in the network. This is considered a L2/L3 network
* interface.
*/ */
@Beta @Beta
public class Interface { public class Interface {
@ -51,9 +52,9 @@ public class Interface {
Set<InterfaceIpAddress> ipAddresses, Set<InterfaceIpAddress> ipAddresses,
MacAddress macAddress, VlanId vlan) { MacAddress macAddress, VlanId vlan) {
this.connectPoint = checkNotNull(connectPoint); this.connectPoint = checkNotNull(connectPoint);
this.ipAddresses = Sets.newHashSet(checkNotNull(ipAddresses)); this.ipAddresses = ipAddresses == null ? Sets.newHashSet() : ipAddresses;
this.macAddress = checkNotNull(macAddress); this.macAddress = macAddress == null ? MacAddress.NONE : macAddress;
this.vlan = checkNotNull(vlan); this.vlan = vlan == null ? VlanId.NONE : vlan;
} }
/** /**

View File

@ -22,6 +22,7 @@ import java.util.Arrays;
*/ */
public class MacAddress { public class MacAddress {
public static final MacAddress NONE = valueOf("a4:23:05:00:00:00");
public static final MacAddress ZERO = valueOf("00:00:00:00:00:00"); public static final MacAddress ZERO = valueOf("00:00:00:00:00:00");
public static final MacAddress BROADCAST = valueOf("ff:ff:ff:ff:ff:ff"); public static final MacAddress BROADCAST = valueOf("ff:ff:ff:ff:ff:ff");