...
SubjectFactory
ties a subject to its subject key, and generates objects that represent the subject.Example: the factory that generates
ConnectPoints
is instantiated as:Code Block language java public static final SubjectFactory<ConnectPoint> CONNECT_POINT_SUBJECT_FACTORY = new SubjectFactory<ConnectPoint>(ConnectPoint.class, "ports") { @Override public ConnectPoint createSubject(String key) { return ConnectPoint.deviceConnectPoint(key); } };
meaning that the key for the JSON field containing port information is keyed on string “ports”, and the factory can create
ConnectPoint
s from a “deviceId:port” string (the argument tocreateSubject
).
ConfigFactory
ties a subject to its config and config key, and generatesConfig
s.Example: The ConfigFactory for
OpticalPortConfig
is defined as:Code Block language java // ConfigFactory<S, C extends Config<S>> new ConfigFactory<ConnectPoint, OpticalPortConfig>(CONNECT_POINT_SUBJECT_FACTORY, OpticalPortConfig.class, "optical") { @Override public OpticalPortConfig createConfig() { return new OpticalPortConfig(); } }
indicating that this
ConfigFactory
can generateOpticalPortConfig
s, and the configuration information for a given optical port can be fetched from the subsystem’s manager using its associated subject (aConnectPoint
in this case). In the JSON structure, the key “basic” can be used to fetch out the values set by theOpticalPortConfig
.
...
The relationship between the subject, config, subject key, and config key are summarized by the following JSON tree:
Code Block | ||
---|---|---|
| ||
{
subject key 1 : {
subject 1 : {
config key 1 : {
attr1 : value1,
attr2 : value2,
...
},
config key 2 : {
...
}
},
subject 2 : {
...
},
subject key 2 {
...
} |
...
For example, a configuration for the device identified by the ID (subject) of:0000ffffffffff0a might look like the following:
Code Block | ||
---|---|---|
| ||
{ "devices" : { "of:0000ffffffffff0a" : { "basic": { "driver": "linc-oe", "type": "ROADM", "latitude": 33.8, "name": "ATL-S10", "longitude": -84.1 } } } } |
...
Indeed, if you were to take a look at BasicDeviceConfig
and its superclass, you will find all of the fields within the “basic” clause above defined in those two classes.
...
Making objects configurable
The network configuration subsystem can be used to configure arbitrary network objects. For an object to be configurable through this subsystem, you must implement the components described in Components. Some things to note are:
SubjectFactory
implementations belong inSubjectFactories
. While you may want to use an existing factory for your subject of choice, you may want to implement a newSubjectFactory
in addition to an existing one if a different key/creation technique is required for a subject.
A
ConfigFactory
must be registered with theNetworkConfigManager
. Adding aConfigFactory
toBasicNetworkConfigs
will cause it to be registered when the subsystem starts up. Alternatively, you may manually invokeNetworkConfigManager.registerConfigFactory()
from the application:Code Block language java // in the application: @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected NetworkConfigRegistry registry; private ConfigFactory configFactory = new ConfigFactory(SubjectFactories.FOO_SUBJECT_FACTORY, FooConfig.class, "foo") { @Override public FooConfig createConfig() { return new FooConfig(); } }; public void register() { registry.registerConfigFactory(configFactory); }
ConfigOperator
s enforce an order of precedence on information depending on their source. As a general rule, the configs supplied by this subsystem override information supplied by providers.
Using the service from applications
As with other services, the two primary ways that an application can use the network configuration subsystem are:
Registering as a
NetworkConfigListener
: this enables the listener to receiveNetworkConfigEvent
s whenever configurations are added, removed, or modified.
Requesting configuarations with
getConfig()
: an application can fetch the config tied to a certain network element given its subject and aConfig
class:Code Block language java public void doConfigThings(Device dev) { // a Device's subject is its ID DeviceId devId = dev.id(); BasicDeviceConfig bdc = configService.getConfig(devId, BasicDeviceConfig.class); // a attribute of a device is if it's allowed in the network model if (!bdc.isAllowed()) { log.warn("This device isn't allowed here!"); removeDevice(devId); } }
...