forked from damianoneill/net
/
model.go
64 lines (54 loc) · 1.87 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package netconf
import (
"encoding/xml"
"fmt"
)
// Defines structs representing netconf messages and notifications.
// Request represents the body of a Netconf RPC request.
type Request string
// HelloMessage defines the message sent/received during session negotiation.
type HelloMessage struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 hello"`
Capabilities []string `xml:"capabilities>capability"`
SessionID uint64 `xml:"session-id,omitempty"`
}
// RPCMessage defines the an rpc request message
type RPCMessage struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc"`
MessageID string `xml:"message-id,attr"`
Methods []byte `xml:",innerxml"`
}
// RPCReply defines the an rpc request message
type RPCReply struct {
XMLName xml.Name `xml:"rpc-reply"`
Errors []RPCError `xml:"rpc-error,omitempty"`
Data string `xml:",innerxml"`
Ok bool `xml:",omitempty"`
RawReply string `xml:"-"`
MessageID string `xml:"message-id,attr"`
}
// RPCError defines an error reply to a RPC request
type RPCError struct {
Type string `xml:"error-type"`
Tag string `xml:"error-tag"`
Severity string `xml:"error-severity"`
Path string `xml:"error-path"`
Message string `xml:"error-message"`
Info string `xml:",innerxml"`
}
// Error generates a string representation of the RPC error
func (re *RPCError) Error() string {
return fmt.Sprintf("netconf rpc [%s] '%s'", re.Severity, re.Message)
}
// Notification defines a specific notification event.
type Notification struct {
XMLName xml.Name
EventTime string
Event string `xml:",innerxml"`
}
// NotificationMessage defines the notification message sent from the server.
type NotificationMessage struct {
XMLName xml.Name //`xml:"notification"`
EventTime string `xml:"eventTime"`
Event Notification `xml:",any"`
}