Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Merge requests
!91
"Overhaul Architecture"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
"Overhaul Architecture"
67-overhaul-architecture
into
develop
Overview
0
Commits
69
Pipelines
25
Changes
1
Merged
Ghost User
requested to merge
67-overhaul-architecture
into
develop
4 years ago
Overview
0
Commits
69
Pipelines
25
Changes
1
Expand
Closes
#67 (closed)
Edited
4 years ago
by
Ghost User
0
0
Merge request reports
Viewing commit
0dd09a00
Prev
Next
Show latest version
1 file
+
0
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
0dd09a00
removed no longer needed functions
· 0dd09a00
Malte Bauch
authored
4 years ago
nucleus/principalNetworkDomain.go
0 → 100644
+
155
−
0
Options
package
nucleus
import
(
"context"
"encoding/json"
"github.com/google/uuid"
)
// PrincipalNetworkDomain provides an
// interface for PND implementations
type
PrincipalNetworkDomain
interface
{
Destroy
()
error
AddSbi
(
SouthboundInterface
)
error
RemoveSbi
(
string
)
error
AddDevice
(
*
Device
)
error
RemoveDevice
(
uuid
.
UUID
)
error
Request
(
uuid
.
UUID
,
string
)
error
RequestAll
(
string
)
error
GetName
()
string
GetDescription
()
string
MarshalDevice
(
uuid
.
UUID
)
(
string
,
error
)
ContainsDevice
(
uuid
.
UUID
)
bool
GetSBIs
()
map
[
string
]
SouthboundInterface
}
type
pndImplementation
struct
{
name
string
description
string
sbi
map
[
string
]
SouthboundInterface
devices
map
[
uuid
.
UUID
]
*
Device
}
//NewPND creates a Principle Network Domain
func
NewPND
(
name
,
description
string
,
sbi
SouthboundInterface
)
PrincipalNetworkDomain
{
sbic
:=
make
(
map
[
string
]
SouthboundInterface
)
sbic
[
"default"
]
=
sbi
devices
:=
make
(
map
[
uuid
.
UUID
]
*
Device
)
return
&
pndImplementation
{
name
:
name
,
description
:
description
,
sbi
:
sbic
,
devices
:
devices
,
}
}
//GetName returns the name of the PND
func
(
pnd
*
pndImplementation
)
GetName
()
string
{
return
pnd
.
name
}
//HasDevice checks if the given device uuid is registered for this PND
func
(
pnd
*
pndImplementation
)
ContainsDevice
(
uuid
uuid
.
UUID
)
bool
{
_
,
exists
:=
pnd
.
devices
[
uuid
]
return
exists
}
//GetDescription returns the current description of the PND
func
(
pnd
*
pndImplementation
)
GetDescription
()
string
{
return
pnd
.
description
}
//GetSBIs returns the registered SBIs
func
(
pnd
*
pndImplementation
)
GetSBIs
()
map
[
string
]
SouthboundInterface
{
return
pnd
.
sbi
}
// Interface satisfaction
func
(
pnd
*
pndImplementation
)
Destroy
()
error
{
return
destroy
()
}
//AddSbi adds a SBI to the PND which will be supported
func
(
pnd
*
pndImplementation
)
AddSbi
(
sbi
SouthboundInterface
)
error
{
return
pnd
.
addSbi
(
sbi
)
}
//AddSbi removes a SBI from the PND
//TODO: this should to recursivly through
//devices and remove the devices using
//this SBI
func
(
pnd
*
pndImplementation
)
RemoveSbi
(
sbiIdentifier
string
)
error
{
return
pnd
.
removeSbi
(
sbiIdentifier
)
}
//AddDevice adds a new device to the PND
func
(
pnd
*
pndImplementation
)
AddDevice
(
device
*
Device
)
error
{
return
pnd
.
addDevice
(
device
)
}
//RemoveDevice removes a device from the PND
func
(
pnd
*
pndImplementation
)
RemoveDevice
(
uuid
uuid
.
UUID
)
error
{
return
pnd
.
removeDevice
(
uuid
)
}
// Actual implementation, bind to struct if
// neccessary
func
destroy
()
error
{
return
nil
}
func
(
pnd
*
pndImplementation
)
addSbi
(
sbi
SouthboundInterface
)
error
{
pnd
.
sbi
[
sbi
.
SbiIdentifier
()]
=
sbi
return
nil
}
func
(
pnd
*
pndImplementation
)
removeSbi
(
sbiIdentifier
string
)
error
{
delete
(
pnd
.
sbi
,
sbiIdentifier
)
return
nil
}
func
(
pnd
*
pndImplementation
)
addDevice
(
device
*
Device
)
error
{
pnd
.
devices
[
device
.
Config
.
Uuid
]
=
device
return
nil
}
func
(
pnd
*
pndImplementation
)
removeDevice
(
uuid
uuid
.
UUID
)
error
{
delete
(
pnd
.
devices
,
uuid
)
return
nil
}
func
(
pnd
*
pndImplementation
)
MarshalDevice
(
uuid
uuid
.
UUID
)
(
string
,
error
)
{
d
:=
pnd
.
devices
[
uuid
]
json
,
err
:=
json
.
MarshalIndent
(
d
.
GoStruct
,
""
,
"
\t
"
)
if
err
!=
nil
{
return
""
,
err
}
return
string
(
json
),
nil
}
//Request sends a request for a specific device
func
(
pnd
*
pndImplementation
)
Request
(
uuid
uuid
.
UUID
,
path
string
)
error
{
d
:=
pnd
.
devices
[
uuid
]
ctx
:=
context
.
Background
()
res
,
err
:=
d
.
Transport
.
Get
(
ctx
,
path
)
if
err
!=
nil
{
return
err
}
err
=
d
.
Transport
.
ProcessResponse
(
res
,
d
.
GoStruct
,
d
.
SBI
.
Schema
())
if
err
!=
nil
{
return
err
}
return
nil
}
//RequestAll sends a request for all registered devices
func
(
pnd
*
pndImplementation
)
RequestAll
(
path
string
)
error
{
for
k
:=
range
pnd
.
devices
{
if
err
:=
pnd
.
Request
(
k
,
path
);
err
!=
nil
{
return
err
}
}
return
nil
}
Loading