-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting implementation of table entries (#26)
* Starting implementation of table entries * Starting on tests for the stores; broken * Fixed go.mod * Adding table entries test scenarios * Adding stores test * Implemented purge - tables only for now * Added skeletal implementation of the controller package
- Loading branch information
Showing
12 changed files
with
2,139 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ | ||
|
||
Files: VERSION .gitreview go.mod go.sum *.json *.png *.ico *.jpg \\ | ||
Files: VERSION .gitreview go.mod go.sum *.json *.png *.ico *.jpg *.txt \\ | ||
*/*.pb.go | ||
Copyright: 2021 Open Networking Foundation | ||
License: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-FileCopyrightText: 2023-present Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package controller implements the core reconciliation controller tying together API, stores, translators and SB | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"github.com/onosproject/onos-api/go/onos/topo" | ||
"github.com/onosproject/onos-control/pkg/api" | ||
"github.com/onosproject/onos-control/pkg/store" | ||
p4info "github.com/p4lang/p4runtime/go/p4/config/v1" | ||
p4api "github.com/p4lang/p4runtime/go/p4/v1" | ||
) | ||
|
||
type deviceController struct { | ||
api.DeviceControl | ||
id topo.ID | ||
endpoint string | ||
translator api.PipelineTranslator | ||
version string | ||
} | ||
|
||
func newDeviceController(id topo.ID, endpoint string, store store.EntityStore, translator api.PipelineTranslator) api.DeviceControl { | ||
return &deviceController{ | ||
id: id, | ||
endpoint: endpoint, | ||
translator: translator, | ||
} | ||
} | ||
|
||
// Read receives a query and returns back all requested control entries on the given channel | ||
func (d *deviceController) Read(ctx context.Context, entities *[]p4api.Entity, ch chan<- []*p4api.Entity) error { | ||
// TODO: Implement me | ||
return nil | ||
} | ||
|
||
// Write applies a set of updates to the device | ||
func (d *deviceController) Write(ctx context.Context, request *[]p4api.Update) error { | ||
// TODO: Implement me | ||
// Write to the store; notify reconciler to translate and contact southbound | ||
return nil | ||
} | ||
|
||
// EmitPacket requests emission of the specified packet onto the data-plane | ||
func (d *deviceController) EmitPacket(ctx context.Context, packetOut *p4api.PacketOut) error { | ||
// TODO: Implement me | ||
// Go directly to the southbound | ||
return nil | ||
} | ||
|
||
// HandlePackets starts handling the packet-in message using the supplied channel and packet handler | ||
func (d *deviceController) HandlePackets(ch chan<- *p4api.PacketIn, handler *api.PacketHandler) { | ||
// Pass the channel and handler directly to the southbound | ||
} | ||
|
||
// Pipeline returns the P4 information describing the high-level device pipeline | ||
func (d *deviceController) Pipeline() *p4info.P4Info { | ||
return d.translator.FromPipeline() | ||
} | ||
|
||
// Version returns the P4Runtime version of the target | ||
func (d *deviceController) Version() string { | ||
if d.version == "" { | ||
// TODO: Implement me | ||
// Issue capabilities request using southbound and capture version here | ||
d.version = "unknown" | ||
} | ||
return d.version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-FileCopyrightText: 2023-present Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package controller implements the core reconciliation controller tying together API, stores, translators and SB | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"github.com/onosproject/onos-api/go/onos/stratum" | ||
"github.com/onosproject/onos-api/go/onos/topo" | ||
"github.com/onosproject/onos-control/pkg/api" | ||
"github.com/onosproject/onos-control/pkg/store" | ||
"sync" | ||
) | ||
|
||
type devicesController struct { | ||
api.Devices | ||
role stratum.P4RoleConfig | ||
stores store.Stores | ||
|
||
mu sync.RWMutex | ||
devices map[topo.ID]*deviceController | ||
} | ||
|
||
// NewController creates a new controller for device control contexts using the supplied role descriptor | ||
// and pipeline translator | ||
func NewController(role stratum.P4RoleConfig, stores store.Stores) api.Devices { | ||
return &devicesController{ | ||
role: role, | ||
stores: stores, | ||
} | ||
} | ||
|
||
// Add requests creation of a new device flow control context using its P4Runtime connection endpoint | ||
func (c *devicesController) Add(ctx context.Context, id topo.ID, p4rtEndpoint string, translator api.PipelineTranslator) (api.DeviceControl, error) { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
if d, ok := c.devices[id]; ok { | ||
return d, nil | ||
} | ||
|
||
store, err := c.stores.Get(ctx, id, translator.FromPipeline()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return newDeviceController(id, p4rtEndpoint, store, translator), nil | ||
} | ||
|
||
// Remove requests removal of device control context | ||
func (c *devicesController) Remove(id topo.ID) { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
delete(c.devices, id) | ||
} | ||
|
||
// Get the device flow control entity by its ID | ||
func (c *devicesController) Get(id topo.ID) api.DeviceControl { | ||
c.mu.RLock() | ||
defer c.mu.RUnlock() | ||
return c.devices[id] | ||
} | ||
|
||
// GetAll returns all device flow control entities presently registered with the manager | ||
func (c *devicesController) GetAll() []api.DeviceControl { | ||
c.mu.RLock() | ||
defer c.mu.RUnlock() | ||
devices := make([]api.DeviceControl, 0, len(c.devices)) | ||
for _, d := range c.devices { | ||
devices = append(devices, d) | ||
} | ||
return devices | ||
} |
Oops, something went wrong.