Package com.tailf.ned
Class NedConnectionBase
Object
com.tailf.ned.NedConnectionBase
- Direct Known Subclasses:
NedCliBase
,NedGenericBase
A NedConnection is the interface used by the NedMux for keeping
track of connections to different devices. One instance of each
type should be registered with the NedMux before the NedMux is
started. Specific sub-classes are defined for cli and generic
neds, see NedCli and NedGeneric.
The life of a specific connection to a backend device is as
follows.
1 Initially an instance is created through the invocation of
the create method, and a connection to the backend
device is set up.
2 a mix of prepare/abort/revert/commit/persist/show/getTransId/
showStatsPath, etc
3 possibly get invocations to the isAlive() method. This method
is involved when the connection is pooled.
4 possibly get an invocation to the reconnect method, and start
over at 2
5 finally one of the close() methods will be involved. The
connection should close the connection to the device and
release all resources.
If the connection is poolable then it may live in the connection
pool. The state of the connection is polled by the connection
pool manager using the isAlive() method.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
close()
This method is invoked when a connection close is forced and no NedWorker is involved.abstract void
This method is invoked when the connection is terminated.abstract void
command
(NedWorker w, String cmdName, ConfXMLParam[] params) This is for any optional commands on the device that are not part of the yang files config data, but is modeled as tailf:actions or rpcs in the device yang files.abstract void
This indicates that the current set of operations should be committed to the running configuration.int
void
createSubscription
(NedWorker w, String stream, String startTime, String filter, int filterType) This method is invoked to create a notification subscription.abstract String
The device_id is originally provided by NCS to properly identify the device.getCapas()
int
long
abstract void
When this method is invoked the NED should produce a transaction id that must be changed if any changes has been made to the configuration since the last time the transaction id was requested.boolean
boolean
identity()
This should return the a unique (among registered NedConnection classes) identity.void
Used for initializing an transaction.boolean
isAlive()
Deprecated.boolean
This method is invoked to check if a connection is still alive.boolean
This method is invoked periodically to keep an connection alive.abstract String[]
modules()
Which YANG modules are covered by the class instance.abstract void
This method is invoked when the currently committed change set should be made permanent.abstract void
Used for resuming a connection found in the connection pool.void
setCapabilities
(NedCapability[] capas) This function is used to set the capabilities for a specific NED.void
setConnectionData
(NedCapability[] capas, NedCapability[] statscapas, boolean wantRevertDiff, NedWorker.TransactionIdMode transMode) This function is used to set the parameters of NedConnection for a specific NED.void
setPlatformData
(ConfXMLParam[] platformData) This function is used to set the platform operational data for a specific NED.void
showStatsFilter
(NedWorker w, int th, ConfPath[] paths) When this method is invoked the NED should populate the provided transaction th with the data corresponding to the filter.void
showStatsFilter
(NedWorker w, int th, NedShowFilter[] filters) When this method is invoked the NED should populate the provided transaction th with the data corresponding to the filter.void
showStatsFilter
(NedWorker w, int th, String[] xpaths) When this method is invoked the NED should populate the provided transaction th with the data corresponding to the filter.void
showStatsPath
(NedWorker w, int th, ConfPath path) When this method is invoked depending on the node type the NED should: * If the path points to the list node or leaf-list node without specifying the key, then the NED should populate the list keys.abstract String
type()
The type is one of "cli" and "generic".void
If the transaction is not completed and the NED has done initialize this method is called to undo the transaction preparations.void
This function is used to set the same capabilities as stored in CDB for a particular device.
-
Constructor Details
-
NedConnectionBase
public NedConnectionBase()
-
-
Method Details
-
getTimeInPool
public long getTimeInPool() -
setConnectionData
public void setConnectionData(NedCapability[] capas, NedCapability[] statscapas, boolean wantRevertDiff, NedWorker.TransactionIdMode transMode) This function is used to set the parameters of NedConnection for a specific NED.- Parameters:
capas
- an array of capabilities for config datastatscapas
- an array of capabilities for stats datawantRevertDiff
- Indicates if the NED should be provided with the edit operations needed to undo the configuration changes done in the prepare method when a transaction is aborted.transMode
- Indicates the mode of Transaction ID supported by the NED. NONE if not supported. If supported, then getTransId() should be implemented. Support for Transaction IDs is required for check-sync action.
-
setCapabilities
This function is used to set the capabilities for a specific NED. It has the same functionality as setConnectionData, but only for config capabilities. This is useful when initializing a NED instance without establishing connection to the device because other connection parameters such as stats capabilities, reverse diff and transaction id mode are irrelevant in this case- Parameters:
capas
- an array of capabilities for config data
-
useStoredCapabilities
public void useStoredCapabilities()This function is used to set the same capabilities as stored in CDB for a particular device. This method can only be used when initializing a NED instance without establishing connection to the device. -
setPlatformData
This function is used to set the platform operational data for a specific NED. This is optional data that can be retrieved and used for instance in service code. It is possible to augment NED specific data into the platform container in the NCS device model. This method is then used to set both standard and augmented data. The ConfXMLParam[] array is expected to start with the platform tag: The following is an example of how the platformData array would be structured in an example with both the NCS standard name, model and version leaves as well as a augmented inventory list with three list elements:ConfXMLParam[] platformData = new ConfXMLParam[] { new ConfXMLParamStart("ncs", "platform"), new ConfXMLParamValue("ncs", "name", new ConfBuf("ios")), new ConfXMLParamValue("ncs", "version", new ConfBuf("15.0M")), new ConfXMLParamValue("ncs", "model", new ConfBuf("7200")), new ConfXMLParamStart("ginv", "inventory"), new ConfXMLParamValue("ginv", "name", new ConfBuf("lx-345")), new ConfXMLParamValue("ginv", "value", new ConfBuf("line-card")), new ConfXMLParamStop("ginv", "inventory"), new ConfXMLParamStart("ginv", "inventory"), new ConfXMLParamValue("ginv", nameStr, new ConfBuf("lx-1001")), new ConfXMLParamValue("ginv", "value", new ConfBuf("line-card")), new ConfXMLParamStop("ginv", "inventory"), new ConfXMLParamStart("ginv", "inventory"), new ConfXMLParamValue("ginv", "name", new ConfBuf("FA1209A4E389")), new ConfXMLParamValue("ginv", "value", new ConfBuf("licence")), new ConfXMLParamStop("ginv", "inventory"), new ConfXMLParamStop("ncs", "platform") }; setPlatformData(platformData);
- Parameters:
platformData
- An ConfXMLParam array containing operational data to be set under the platform container in the device model. Expected to start with the platform tag. If the platform container is augmented with some user specific model such data should also be part of this array to be set at connection time.
-
connection_id
public int connection_id() -
getConnectionId
public int getConnectionId() -
getCapas
-
getStatsCapas
-
getWantRevertDiff
public boolean getWantRevertDiff() -
getTransactionIdMode
-
getSystemStateData
-
getUseStoredCapas
public boolean getUseStoredCapas() -
device_id
The device_id is originally provided by NCS to properly identify the device. It is the name used for the device by NCS in the list of devices. -
type
The type is one of "cli" and "generic". This information is sent to NCS when the NedMux is started to let NCS know how to communicate with each device. -
modules
Which YANG modules are covered by the class instance. This information is defined by the setConnectionData() call and is sent to NCS after initiating a new connection, or when re-establishing a connection. The modules() method is not actually used. -
identity
This should return the a unique (among registered NedConnection classes) identity. It will be used by NCS when creating new connections to control which of the registered NedConnection classes to use. -
commit
This indicates that the current set of operations should be committed to the running configuration. When completed the w.commitResponse() method should be invoked. Devices that does not support commit() should invoke the w.commitResponse() method without delay. On error invoke the w.error(NedCmd.COMMIT, Error, Reason) method.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.timeout
- If the commit operation does not complete within 'timeout' seconds the operation should be aborted.- Throws:
Exception
-
persist
This method is invoked when the currently committed change set should be made permanent. This corresponds to copying the running configuration to the startup configuration, on a running/startup device, or issuing the confirming commit operation on a device that supports that. When completed the w.persistResponse() should be invoked. On error invoke the w.error(NedCmd.PERSIST,Error, Reason) method.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
close
This method is invoked when the connection is terminated. It is not invoked when placing the connection in the connection pool. No response is required, but trace messages may be generated during the close down.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
close
public abstract void close()This method is invoked when a connection close is forced and no NedWorker is involved. This typically occurs when a connection is removed from the connection pool. No response or trace messages can be sent during the operation. -
isAlive
Deprecated.Use the methodisAlive(NedWorker)
instead. If theisAlive(NedWorker)
method is implemented in the NED, this method will not be invoked. The NED must implement one of these methods. -
isAlive
This method is invoked to check if a connection is still alive. When a connection is stored in the connection pool it will periodically be polled to see if it is alive. If false is returned the connection will be closed using the close() method invocation.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
-
keepAlive
This method is invoked periodically to keep an connection alive. If false is returned the connection will be closed using the close() method invocation.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.
-
command
This is for any optional commands on the device that are not part of the yang files config data, but is modeled as tailf:actions or rpcs in the device yang files.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.cmdName
- Name of the command (path to action?)params
-- Throws:
Exception
-
showStatsPath
When this method is invoked depending on the node type the NED should: * If the path points to the list node or leaf-list node without specifying the key, then the NED should populate the list keys. The NED should also set the TTL on the list node or individual list instances. It may choose to write more data into the list instances in which case it may populate TTL values for this data as well. * If the path indicates a list entry, presence container, empty leaf or a leaf-list instance, then the NED should indicate the existence of this node in the data tree and return the corresponding TTL value. It may populate more data into the list instance or presence container in which case it may populate TTL values for this data as well. * If the path points to a leaf, then the NED should write the value of the leaf and indicate its TTL. * If the NED chooses to populate the entire subtree below the path and has nothing more to fetch, it should indicate so in the TTL value. The TTL value for this path will act as the default TTL. The abovementioned operations should be performed on the provided transaction th. The method should indicate its return status by invoking the method w.error() or w.showStatsPathResponse()- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.th
- a transaction handler that can be used in Maapipath
- a ConfPath indication which list is requested- Throws:
Exception
-
showStatsFilter
When this method is invoked the NED should populate the provided transaction th with the data corresponding to the filter. This method will be invoked if the NED announces the http://tail-f.com/ns/ncs-ned/show-stats?format=path capability. The method should indicate its return status by invoking the method w.error() or w.showStatsFilterResponse()- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.th
- a transaction handler that can be used in Maapipaths
- an array of ConfPath objects indicating what is requested- Throws:
Exception
-
showStatsFilter
When this method is invoked the NED should populate the provided transaction th with the data corresponding to the filter. This method will be invoked if the NED announces the http://tail-f.com/ns/ncs-ned/show-stats?format=xpath capability. The method should indicate its return status by invoking the method w.error() or w.showStatsFilterResponse()- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.th
- a transaction handler that can be used in Maapixpaths
- an array of xpath strings indicating what is requested- Throws:
Exception
-
showStatsFilter
When this method is invoked the NED should populate the provided transaction th with the data corresponding to the filter. This method will be invoked if the NED announces the http://tail-f.com/ns/ncs-ned/show-stats?format=filter capability. The method should indicate its return status by invoking the method w.error() or w.showStatsFilterResponse()- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.th
- a transaction handler that can be used in Maapifilters
- an array of NedShowFilter indicating what is requested- Throws:
Exception
-
getTransId
When this method is invoked the NED should produce a transaction id that must be changed if any changes has been made to the configuration since the last time the transaction id was requested. The transaction id can either be requested from the system, or calculated by the callback, for example by calculating an MD5 checksum of the configuration text. The method should indicate its return status by invoking the method w.error() or w.getTransIdResponse() The method should be implemented if the NED claimed a NedWorker.TransactionIdMode which is not NONE in setConnectionData().- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
reconnect
Used for resuming a connection found in the connection pool.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
initialize
Used for initializing an transaction. For instance if locking or other transaction preparations are necessary, they should be performed here. Note, that this method has a proper implementation in the base class and is therefore not necessary to override if no NED specific transaction preparations are needed. The method should indicate its return status by invoking the method w.error() or w.initializeResponse() If the NED has claimed a NedWorker.TransactionIdMode other than not NONE a transaction id must be produced in the response same as for the getTransId() call.- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, ie for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
uninitialize
If the transaction is not completed and the NED has done initialize this method is called to undo the transaction preparations. That is restoring the NED to the state before initialize. Note, that this method has a proper implementation in the base class and is therefore not necessary to override if no NED specific operations was performed in initialize. The method should indicate its return status by invoking the method w.error() or w.uninitializeResponse()- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.- Throws:
Exception
-
createSubscription
public void createSubscription(NedWorker w, String stream, String startTime, String filter, int filterType) throws Exception This method is invoked to create a notification subscription. After the subscription has been created the NedWorker can send notifiction messages, in the NETCONF notification format, with the w.notification() method. The method should indicate its return status by invoking the method w.error() or w.createSubscriptionResponse() Errors like these are non-recoverable, meaning NCS will not attempt to re-establish the notification stream: w.error(NedCmd.CREATE_SUBSCRIPTION, NedErrorCode.NED_EXTERNAL_ERROR, "..."); When NedErrorCode.CONNECT_CONNECTION_REFUSED error code is provided NCS will retry to re-establish the notification stream every /devices/device/notifications/subscription/reconnect-interval seconds. w.error(NedCmd.CREATE_SUBSCRIPTION, NedErrorCode.CONNECT_CONNECTION_REFUSED, "");- Parameters:
w
- The NedWorker instance currently responsible for driving the communication between NCS and the device. This NedWorker instance should be used when communicating with NCS, i.e, for sending responses, errors, and trace messages. It is also implements the NedTracer API and can be used in, for example, the SSHSession as a tracer.stream
- The notification stream to establish the subscription on.startTime
- Trigger the replay feature and indicate that the replay should start at the time specified. If null, this is not a replay subscription. It is not valid to specify start times that are later than the current time. If the time specified is earlier than the log can support, the replay will begin with the earliest available notification. This parameter is of dateTime XML schema type and compliant to RFC 3339. Implementations must support time zones.filter
- Indicates which subset of all possible events is of interest. The format of this parameter is the same as that of the filter parameter in the NETCONF protocol operations. If not present, all events not precluded by other parameters will be sent.filterType
- Indicates the type of filter if it is used:- Throws:
Exception
- See Also:
-
isAlive(NedWorker)
instead.