SDN Controller Programming Guide

153
if (!node.path(IP_ADDRESS).isMissingNode()) {
device.setIpAddress(IpAddress
.valueOf(node.get(IP_ADDRESS).asText()));
}
if (!node.path(FRIENDLY_NAME).isMissingNode()) {
device.setFriendlyName(node.get(FRIENDLY_NAME).asText());
}
if (!node.path(ACTIVE_STATE).isMissingNode()) {
device.setActiveState(ActiveState.valueOf(
node.get(ACTIVE_STATE).asText()));
}
return device;
}
@Override
public ObjectNode encode(Switch device) {
ObjectNode node = mapper.createObjectNode();
node.put(MAC_ADDRESS, device.getMacAddress().toString());
if (device.getId() != null) {
node.put(ID, device.getId().getValue().longValue());
}
if (device.getIpAddress() != null) {
node.put(IP_ADDRESS, device.getIpAddress().toString());
}
if (device.getFriendlyName() != null) {
node.put(FRIENDLY_NAME, device.getFriendlyName());
}
if (device.getActiveState() != null) {
node.put(ACTIVE_STATE, device.getActiveState().name());
}
return node;
}
private static void validateMandatoryFields(ObjectNode node,
String... fields) throws IllegalArgumentException {
if (fields != null) {