Luca Prete
Committed by Gerrit Code Review

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

Change-Id: I6663504f63df25260aa62c28337cdadb83dfd361
...@@ -43,7 +43,7 @@ public class InterfaceAddCommand extends AbstractShellCommand { ...@@ -43,7 +43,7 @@ public class InterfaceAddCommand extends AbstractShellCommand {
43 43
44 @Option(name = "-m", aliases = "--mac", 44 @Option(name = "-m", aliases = "--mac",
45 description = "MAC address of the interface", 45 description = "MAC address of the interface",
46 - required = true, multiValued = false) 46 + required = false, multiValued = false)
47 private String mac = null; 47 private String mac = null;
48 48
49 @Option(name = "-i", aliases = "--ip", 49 @Option(name = "-i", aliases = "--ip",
...@@ -68,10 +68,12 @@ public class InterfaceAddCommand extends AbstractShellCommand { ...@@ -68,10 +68,12 @@ public class InterfaceAddCommand extends AbstractShellCommand {
68 } 68 }
69 } 69 }
70 70
71 + MacAddress macAddr = mac == null ? null : MacAddress.valueOf(mac);
72 +
71 VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan)); 73 VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan));
72 74
73 Interface intf = new Interface(ConnectPoint.deviceConnectPoint(connectPoint), 75 Interface intf = new Interface(ConnectPoint.deviceConnectPoint(connectPoint),
74 - ipAddresses, MacAddress.valueOf(mac), vlanId); 76 + ipAddresses, macAddr, vlanId);
75 77
76 interfaceService.add(intf); 78 interfaceService.add(intf);
77 } 79 }
......
...@@ -39,7 +39,6 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -39,7 +39,6 @@ public class InterfaceConfig extends Config<ConnectPoint> {
39 public static final String MAC = "mac"; 39 public static final String MAC = "mac";
40 public static final String VLAN = "vlan"; 40 public static final String VLAN = "vlan";
41 41
42 - public static final String MAC_MISSING_ERROR = "Must have a MAC address for each interface";
43 public static final String CONFIG_VALUE_ERROR = "Error parsing config value"; 42 public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
44 43
45 /** 44 /**
...@@ -55,15 +54,12 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -55,15 +54,12 @@ public class InterfaceConfig extends Config<ConnectPoint> {
55 for (JsonNode intfNode : array) { 54 for (JsonNode intfNode : array) {
56 Set<InterfaceIpAddress> ips = getIps(intfNode); 55 Set<InterfaceIpAddress> ips = getIps(intfNode);
57 56
58 - if (intfNode.path(MAC).isMissingNode()) { 57 + String mac = intfNode.path(MAC).asText();
59 - throw new ConfigException(MAC_MISSING_ERROR); 58 + MacAddress macAddr = mac.isEmpty() ? null : MacAddress.valueOf(mac);
60 - }
61 -
62 - MacAddress mac = MacAddress.valueOf(intfNode.path(MAC).asText());
63 59
64 VlanId vlan = getVlan(intfNode); 60 VlanId vlan = getVlan(intfNode);
65 61
66 - interfaces.add(new Interface(subject, ips, mac, vlan)); 62 + interfaces.add(new Interface(subject, ips, macAddr, vlan));
67 } 63 }
68 } catch (IllegalArgumentException e) { 64 } catch (IllegalArgumentException e) {
69 throw new ConfigException(CONFIG_VALUE_ERROR, e); 65 throw new ConfigException(CONFIG_VALUE_ERROR, e);
...@@ -79,7 +75,10 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -79,7 +75,10 @@ public class InterfaceConfig extends Config<ConnectPoint> {
79 */ 75 */
80 public void addInterface(Interface intf) { 76 public void addInterface(Interface intf) {
81 ObjectNode intfNode = array.addObject(); 77 ObjectNode intfNode = array.addObject();
82 - intfNode.put(MAC, intf.mac().toString()); 78 +
79 + if (intf.mac() != null) {
80 + intfNode.put(MAC, intf.mac().toString());
81 + }
83 82
84 if (!intf.ipAddresses().isEmpty()) { 83 if (!intf.ipAddresses().isEmpty()) {
85 intfNode.set(IPS, putIps(intf.ipAddresses())); 84 intfNode.set(IPS, putIps(intf.ipAddresses()));
......
...@@ -30,7 +30,8 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -30,7 +30,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
30 30
31 /** 31 /**
32 * An Interface maps network configuration information (such as addresses and 32 * An Interface maps network configuration information (such as addresses and
33 - * vlans) to a port in the network. 33 + * vlans) to a port in the network. This is considered a L2/L3 network
34 + * interface.
34 */ 35 */
35 @Beta 36 @Beta
36 public class Interface { 37 public class Interface {
...@@ -51,9 +52,9 @@ public class Interface { ...@@ -51,9 +52,9 @@ public class Interface {
51 Set<InterfaceIpAddress> ipAddresses, 52 Set<InterfaceIpAddress> ipAddresses,
52 MacAddress macAddress, VlanId vlan) { 53 MacAddress macAddress, VlanId vlan) {
53 this.connectPoint = checkNotNull(connectPoint); 54 this.connectPoint = checkNotNull(connectPoint);
54 - this.ipAddresses = Sets.newHashSet(checkNotNull(ipAddresses)); 55 + this.ipAddresses = ipAddresses == null ? Sets.newHashSet() : ipAddresses;
55 - this.macAddress = checkNotNull(macAddress); 56 + this.macAddress = macAddress == null ? MacAddress.NONE : macAddress;
56 - this.vlan = checkNotNull(vlan); 57 + this.vlan = vlan == null ? VlanId.NONE : vlan;
57 } 58 }
58 59
59 /** 60 /**
......
...@@ -22,6 +22,7 @@ import java.util.Arrays; ...@@ -22,6 +22,7 @@ import java.util.Arrays;
22 */ 22 */
23 public class MacAddress { 23 public class MacAddress {
24 24
25 + public static final MacAddress NONE = valueOf("a4:23:05:00:00:00");
25 public static final MacAddress ZERO = valueOf("00:00:00:00:00:00"); 26 public static final MacAddress ZERO = valueOf("00:00:00:00:00:00");
26 public static final MacAddress BROADCAST = valueOf("ff:ff:ff:ff:ff:ff"); 27 public static final MacAddress BROADCAST = valueOf("ff:ff:ff:ff:ff:ff");
27 28
......