SDN Controller Programming Guide
120
public Switch(MacAddress macAddress) {
this(null, macAddress);
}
public Switch(Id<Switch, Long> id, MacAddress macAddress) {
super(id);
if (macAddress == null) {
throw new NullPointerException("macAddress cannot be null");
}
this.macAddress = macAddress;
}
// Implement getters for immutable fields: MAC Address.
// Implement setters and getters for mutable fields: IP address,
// friendly name and active status.
// Good practice to override the following methods on transport objects:
// equals(Object), hashCode() and toString()
...
}
ActiveState.java:
package com.hp.hm.model;
public enum ActiveState {
ON,
OFF
}
The Switch model object implements the Transportable interface which is part of the HP VAN SDN
Controller Framework; AbstractModel offers a partial implementation of such interface. In order to
use such an interface and its partial implementation the root POM file must resolve the
dependencies. The root POM file is used to resolve the dependencies because these required
modules are used at all application levels (Presentation logic, controller logic, business logic, cross-
cutting logic, and so on), thus all the application modules will depend on them. Later it’ll be shown
how specific dependencies to certain modules are added into the specific module POM file.
NOTE
At this point
AbstractModel
and
Transportable
are used just to denote that
Switch
follows the data
transfer object pattern [32].
AbstractModel
is a convenient partial implementation because it properly
overrides
equals()
and
hashCode()
methods. However, if the HP VAN SDN Controller’s persistence
framework is used to persiste data, then data transfer objects take an explicit role and they must follow
certan hierarchically constraints. At the time this document was written, the HP VAN SDN Controller
made use of two different persistence frameworks: Relational (JPA) and Non-Relational (Cassandra).
These frameworks will be unified in the future, but at this phase two different interfaces for transfer
objects are defined: one to use in relational models and one to use in non-relational. See Persistence
on page 79 to choose the right interface if data will be persisted.