From 81fb52a25f759fe7f6ec9f70a5b900391aa6e1b9 Mon Sep 17 00:00:00 2001 From: andersong-precisionOT Date: Tue, 14 Jan 2025 09:16:16 -0500 Subject: [PATCH 1/3] Update operations.go Filtered stream added to operations.go --- netconf/operations.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/netconf/operations.go b/netconf/operations.go index 8e72542..f6af1f5 100644 --- a/netconf/operations.go +++ b/netconf/operations.go @@ -51,6 +51,29 @@ func (session *Session) CreateNotificationStream( return nil } +func (session *Session) CreateNotificationStreamFiltered( + timeout int32, stopTime string, startTime string, filter string, stream string, callback Callback, +) error { + if session.IsNotificationStreamCreated { + return fmt.Errorf( + "there is already an active notification stream subscription. " + + "A session can only support one notification stream at the time", + ) + } + session.Listener.Register(message.NetconfNotificationStreamHandler, callback) + sub := message.NewCreateSubscriptionFiltered(stopTime, startTime, stream, filter) + rpc, err := session.SyncRPC(sub, timeout) + if err != nil { + errMsg := "fail to create notification stream" + if rpc != nil && len(rpc.Errors) != 0 { + errMsg += fmt.Sprintf(" with errors: %s", rpc.Errors) + } + return fmt.Errorf("%s: %w", errMsg, err) + } + session.IsNotificationStreamCreated = true + return nil +} + // AsyncRPC is used to send an RPC method and receive the response asynchronously. func (session *Session) AsyncRPC(operation message.RPCMethod, callback Callback) error { From e8b1c8fcc596d123ef945cb9be40353475092611 Mon Sep 17 00:00:00 2001 From: andersong-precisionOT Date: Tue, 14 Jan 2025 09:17:33 -0500 Subject: [PATCH 2/3] Update notification.go Filter options added to notification.go --- netconf/message/notification.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/netconf/message/notification.go b/netconf/message/notification.go index b25f3e1..f60e4e0 100644 --- a/netconf/message/notification.go +++ b/netconf/message/notification.go @@ -74,6 +74,7 @@ type CreateSubscription struct { type CreateSubscriptionData struct { XMLNS string `xml:"xmlns,attr"` Stream string `xml:"stream,omitempty"` // default is NETCONF + Filter string `xml:",innerxml"` StartTime string `xml:"startTime,omitempty"` StopTime string `xml:"stopTime,omitempty"` } @@ -82,7 +83,7 @@ type CreateSubscriptionData struct { func NewCreateSubscriptionDefault() *CreateSubscription { var rpc CreateSubscription var sub = &CreateSubscriptionData{ - NetconfNotificationXmlns, "", "", "", + NetconfNotificationXmlns, "", "", "", "", } rpc.Subscription = *sub rpc.MessageID = uuid() @@ -93,7 +94,18 @@ func NewCreateSubscriptionDefault() *CreateSubscription { func NewCreateSubscription(stopTime string, startTime string, stream string) *CreateSubscription { var rpc CreateSubscription var sub = &CreateSubscriptionData{ - NetconfNotificationXmlns, stream, startTime, stopTime, + NetconfNotificationXmlns, stream, "", startTime, stopTime, + } + rpc.Subscription = *sub + rpc.MessageID = uuid() + return &rpc +} + +// NewCreateSubscriptionFiltered can be used to create a `create-subscription` message with a filter parameter +func NewCreateSubscriptionFiltered(stopTime string, startTime string, stream string, filter string) *CreateSubscription { + var rpc CreateSubscription + var sub = &CreateSubscriptionData{ + NetconfNotificationXmlns, stream, filter, startTime, stopTime, } rpc.Subscription = *sub rpc.MessageID = uuid() From d92a622b0717a164ebbb877869552ed1281f9ff0 Mon Sep 17 00:00:00 2001 From: andersong-precisionOT Date: Wed, 22 Jan 2025 13:36:20 -0500 Subject: [PATCH 3/3] Removed filter functions and parameterized existing ones --- netconf/message/notification.go | 13 +------------ netconf/operations.go | 25 +------------------------ 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/netconf/message/notification.go b/netconf/message/notification.go index f60e4e0..893baee 100644 --- a/netconf/message/notification.go +++ b/netconf/message/notification.go @@ -91,18 +91,7 @@ func NewCreateSubscriptionDefault() *CreateSubscription { } // NewCreateSubscription can be used to create a `create-subscription` message. -func NewCreateSubscription(stopTime string, startTime string, stream string) *CreateSubscription { - var rpc CreateSubscription - var sub = &CreateSubscriptionData{ - NetconfNotificationXmlns, stream, "", startTime, stopTime, - } - rpc.Subscription = *sub - rpc.MessageID = uuid() - return &rpc -} - -// NewCreateSubscriptionFiltered can be used to create a `create-subscription` message with a filter parameter -func NewCreateSubscriptionFiltered(stopTime string, startTime string, stream string, filter string) *CreateSubscription { +func NewCreateSubscription(stopTime string, startTime string, stream string, filter string) *CreateSubscription { var rpc CreateSubscription var sub = &CreateSubscriptionData{ NetconfNotificationXmlns, stream, filter, startTime, stopTime, diff --git a/netconf/operations.go b/netconf/operations.go index f6af1f5..b1dc61b 100644 --- a/netconf/operations.go +++ b/netconf/operations.go @@ -29,29 +29,6 @@ import ( // TODO limitation - for now, we can only register one stream per session, because when a notification is received // there is no way to attribute it to a specific stream func (session *Session) CreateNotificationStream( - timeout int32, stopTime string, startTime string, stream string, callback Callback, -) error { - if session.IsNotificationStreamCreated { - return fmt.Errorf( - "there is already an active notification stream subscription. " + - "A session can only support one notification stream at the time", - ) - } - session.Listener.Register(message.NetconfNotificationStreamHandler, callback) - sub := message.NewCreateSubscription(stopTime, startTime, stream) - rpc, err := session.SyncRPC(sub, timeout) - if err != nil { - errMsg := "fail to create notification stream" - if rpc != nil && len(rpc.Errors) != 0 { - errMsg += fmt.Sprintf(" with errors: %s", rpc.Errors) - } - return fmt.Errorf("%s: %w", errMsg, err) - } - session.IsNotificationStreamCreated = true - return nil -} - -func (session *Session) CreateNotificationStreamFiltered( timeout int32, stopTime string, startTime string, filter string, stream string, callback Callback, ) error { if session.IsNotificationStreamCreated { @@ -61,7 +38,7 @@ func (session *Session) CreateNotificationStreamFiltered( ) } session.Listener.Register(message.NetconfNotificationStreamHandler, callback) - sub := message.NewCreateSubscriptionFiltered(stopTime, startTime, stream, filter) + sub := message.NewCreateSubscription(stopTime, startTime, stream, filter) rpc, err := session.SyncRPC(sub, timeout) if err != nil { errMsg := "fail to create notification stream"