summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/netconf-executor/src/main
diff options
context:
space:
mode:
authorOleg Mitsura <oleg.mitsura@amdocs.com>2019-04-08 16:47:45 -0400
committerOleg Mitsura <oleg.mitsura@amdocs.com>2019-04-08 16:47:45 -0400
commitee01c09ce809a7d5171662e564a98c1ec1ea40fc (patch)
treec0f7655eed5f56d18f479aa532ea378891915755 /ms/blueprintsprocessor/functions/netconf-executor/src/main
parentdbd67ee741f4e3d255dfbe2674ad45ea854598fd (diff)
netconf-executor tests: adding MessageStateTests
Issue-ID: CCSDK-1126 Change-Id: I6351163cf6e157eda41a47b07e53dfaac00f5da5 Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main')
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt94
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt2
3 files changed, 45 insertions, 54 deletions
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt
index cfdd0104c..23982dcb5 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt
@@ -16,6 +16,5 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api
interface NetconfSessionListener {
-
- fun notify(event: NetconfReceivedEvent)
+ fun accept(event: NetconfReceivedEvent)
}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt
index 4199998a8..12e3b83da 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt
@@ -57,11 +57,7 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
val cInt = bufferReader.read()
if (cInt == -1) {
log.error("$deviceInfo: Received cInt = -1")
-// bufferReader.close()
socketClosed = true
-// sessionListener.notify(NetconfReceivedEvent(
-// NetconfReceivedEvent.Type.SESSION_CLOSED,
-// deviceInfo = deviceInfo))
}
val c = cInt.toChar()
state = state.evaluateChar(c)
@@ -71,7 +67,7 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
if (deviceReply == RpcMessageUtils.END_PATTERN) {
socketClosed = true
bufferReader.close()
- sessionListener.notify(NetconfReceivedEvent(
+ sessionListener.accept(NetconfReceivedEvent(
NetconfReceivedEvent.Type.DEVICE_UNREGISTERED,
deviceInfo = deviceInfo))
} else {
@@ -84,7 +80,7 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
if (!NetconfMessageUtils.validateChunkedFraming(deviceReply)) {
log.debug("$deviceInfo: Received badly framed message $deviceReply")
socketClosed = true
- sessionListener.notify(NetconfReceivedEvent(
+ sessionListener.accept(NetconfReceivedEvent(
NetconfReceivedEvent.Type.DEVICE_ERROR,
deviceInfo = deviceInfo))
} else {
@@ -98,98 +94,89 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
} catch (e: IOException) {
log.warn("$deviceInfo: Fail while reading from channel", e)
- sessionListener.notify(NetconfReceivedEvent(
+ sessionListener.accept(NetconfReceivedEvent(
NetconfReceivedEvent.Type.DEVICE_ERROR,
deviceInfo = deviceInfo))
}
}
- private enum class NetconfMessageState {
+ /**
+ * State machine for the Netconf message parser
+ */
+ internal enum class NetconfMessageState {
NO_MATCHING_PATTERN {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == ']') {
- FIRST_BRACKET
- } else if (c == '\n') {
- FIRST_LF
- } else {
- this
+ return when (c) {
+ ']' -> FIRST_BRACKET
+ '\n' -> FIRST_LF
+ else -> this
}
}
},
FIRST_BRACKET {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == ']') {
- SECOND_BRACKET
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ ']' -> SECOND_BRACKET
+ else -> NO_MATCHING_PATTERN
}
}
},
SECOND_BRACKET {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == '>') {
- FIRST_BIGGER
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ '>' -> FIRST_BIGGER
+ else -> NO_MATCHING_PATTERN
}
}
},
FIRST_BIGGER {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == ']') {
- THIRD_BRACKET
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ ']' -> THIRD_BRACKET
+ else -> NO_MATCHING_PATTERN
}
}
},
THIRD_BRACKET {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == ']') {
- ENDING_BIGGER
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ ']' -> ENDING_BIGGER
+ else -> NO_MATCHING_PATTERN
}
}
},
ENDING_BIGGER {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == '>') {
- END_PATTERN
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ '>' -> END_PATTERN
+ else -> NO_MATCHING_PATTERN
}
}
},
FIRST_LF {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == '#') {
- FIRST_HASH
- } else if (c == ']') {
- FIRST_BRACKET
- } else if (c == '\n') {
- this
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ '#' -> FIRST_HASH
+ ']' -> FIRST_BRACKET
+ '\n' -> this
+ else -> NO_MATCHING_PATTERN
}
}
},
FIRST_HASH {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == '#') {
- SECOND_HASH
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ '#' -> SECOND_HASH
+ else -> NO_MATCHING_PATTERN
}
}
},
SECOND_HASH {
override fun evaluateChar(c: Char): NetconfMessageState {
- return if (c == '\n') {
- END_CHUNKED_PATTERN
- } else {
- NO_MATCHING_PATTERN
+ return when (c) {
+ '\n' -> END_CHUNKED_PATTERN
+ else -> NO_MATCHING_PATTERN
}
}
},
@@ -204,6 +191,11 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
}
};
+ /**
+ * Evaluate next transition state based on current state and the character read
+ * @param c character read in
+ * @return result of lookup of transition to the next {@link NetconfMessageState}
+ */
internal abstract fun evaluateChar(c: Char): NetconfMessageState
}
@@ -234,7 +226,7 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
} else {
log.error("$deviceInfo: Invalid message received: \n $deviceReply")
}
- sessionListener.notify(NetconfReceivedEvent(
+ sessionListener.accept(NetconfReceivedEvent(
NetconfReceivedEvent.Type.DEVICE_REPLY,
deviceReply,
NetconfMessageUtils.getMsgId(deviceReply),
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
index ae4d8444c..d0f4a1dfb 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
@@ -263,7 +263,7 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
}
inner class NetconfSessionListenerImpl : NetconfSessionListener {
- override fun notify(event: NetconfReceivedEvent) {
+ override fun accept(event: NetconfReceivedEvent) {
val messageId = event.messageId
when (event.type) {