You need to sign in or sign up before continuing.
Newer
Older
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package api
import (
ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd"
tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/change"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/device"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/networkdomain"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/southbound"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/store"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/errors"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
)
type PrincipalNetworkDomainAdapter struct {
id uuid.UUID
endpoint string
}
func NewAdapter(id, endpoint string) (networkdomain.NetworkDomain, error) {
pid, err := uuid.Parse(id)
if err != nil {
return nil, err
}
return &PrincipalNetworkDomainAdapter{
id: pid,
endpoint: endpoint,
}, nil
}
func (p *PrincipalNetworkDomainAdapter) Destroy() error {
return &errors.ErrNotYetImplemented{}
}
func (p *PrincipalNetworkDomainAdapter) AddSbi(s southbound.SouthboundInterface) error {
return &errors.ErrNotYetImplemented{}
}
func (p *PrincipalNetworkDomainAdapter) RemoveSbi(uuid.UUID) error {
return &errors.ErrNotYetImplemented{}
}
// AddDevice adds a new device to the controller. The device name is optional.
// If no name is provided a name will be generated upon device creation.
func (p *PrincipalNetworkDomainAdapter) AddDevice(name string, opts *tpb.TransportOption, sid uuid.UUID) error {
resp, err := addDevice(p.endpoint, name, opts, sid, p.ID())
if err != nil {
return err
}
log.Info(resp)
return nil
}
// GetDevice requests one or multiple devices belonging to a given
// PrincipalNetworkDomain from the controller. If no device identifier
// is provided, all devices are requested.
func (p *PrincipalNetworkDomainAdapter) GetDevice(identifier string) (device.Device, error) {
resp, err := getDevice(p.endpoint, p.id.String(), identifier)
if err != nil {
return nil, err
}
// TODO: Parse into device.Device
log.Info(resp)
return nil, nil
}
func (p *PrincipalNetworkDomainAdapter) RemoveDevice(did uuid.UUID) error {
resp, err := deleteDevice(p.endpoint, p.id.String(), did.String())
if err != nil {
return err
}
log.Info(resp)
return nil
}
func (p *PrincipalNetworkDomainAdapter) Devices() []uuid.UUID {
return nil
}
func (p *PrincipalNetworkDomainAdapter) ChangeOND(uuid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) error {
var v string
if len(value) != 0 {
v = value[0]
}
resp, err := changeRequest(p.endpoint, uuid.String(), p.id.String(), path, v, operation)
if err != nil {
return err
}
log.Info(resp)
return err
}
func (p *PrincipalNetworkDomainAdapter) Request(did uuid.UUID, path string) error {
resp, err := getPath(p.endpoint, p.id.String(), did.String(), path)
if err != nil {
return err
}
log.Info(resp)
return nil
}
func (p *PrincipalNetworkDomainAdapter) RequestAll(string) error {
return &errors.ErrNotYetImplemented{}
}
func (p *PrincipalNetworkDomainAdapter) GetName() string {
return ""
}
func (p *PrincipalNetworkDomainAdapter) GetDescription() string {
return ""
}
func (p *PrincipalNetworkDomainAdapter) MarshalDevice(string) (string, error) {
return "", &errors.ErrNotYetImplemented{}
}
func (p *PrincipalNetworkDomainAdapter) ContainsDevice(uuid.UUID) bool {
return false
}
func (p *PrincipalNetworkDomainAdapter) GetSBIs() store.Store {
return nil
}
func (p *PrincipalNetworkDomainAdapter) ID() uuid.UUID {
return p.id
}
func (p *PrincipalNetworkDomainAdapter) PendingChanges() []uuid.UUID {
resp, err := getChanges(p.endpoint, p.id.String())
if err != nil {
log.Error(err)
return nil
}
return filterChanges(ppb.Change_PENDING, resp)
}
func (p *PrincipalNetworkDomainAdapter) CommittedChanges() []uuid.UUID {
resp, err := getChanges(p.endpoint, p.id.String())
if err != nil {
log.Error(err)
return nil
}
return filterChanges(ppb.Change_COMMITTED, resp)
}
func (p *PrincipalNetworkDomainAdapter) GetChange(uuid.UUID, ...int) (change.Change, error) {
return nil, &errors.ErrNotYetImplemented{}
}
func (p *PrincipalNetworkDomainAdapter) Commit(cuid uuid.UUID) error {
resp, err := commit(p.endpoint, p.id.String(), cuid.String())
if err != nil {
return err
}
log.Info(resp)
return nil
}
func (p *PrincipalNetworkDomainAdapter) Confirm(cuid uuid.UUID) error {
resp, err := confirm(p.endpoint, p.id.String(), cuid.String())
if err != nil {
return err
}
log.Info(resp)
return nil
}
func filterChanges(state ppb.Change_State, resp *ppb.GetResponse) []uuid.UUID {
changes := make([]uuid.UUID, 0)
for _, ch := range resp.Change {
if ch.State == ppb.Change_PENDING {
id, _ := uuid.Parse(ch.Id)
changes = append(changes, id)
}
}
return changes
}