Skip to content

Commit

Permalink
Project import generated by Copybara. (#86)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 30a2f95d5b9e12f4c954f1ecc02b0c720314ab95

Co-authored-by: Aalyria Technologies, Inc. <[email protected]>
  • Loading branch information
ciarand and Aalyria Technologies, Inc. committed Jul 10, 2024
1 parent 507262e commit 7a8d580
Show file tree
Hide file tree
Showing 24 changed files with 400 additions and 444 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bazel_dep(name = "gazelle", version = "0.35.0")
bazel_dep(name = "container_structure_test", version = "1.16.0", dev_dependency = True)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.3")
go_sdk.download(version = "1.22.5")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ go_rules_dependencies()

# Install the Go toolchains. (https://github.com/bazelbuild/rules_go/blob/master/go/toolchains.rst#go-toolchain)
go_register_toolchains(
version = "1.22.3",
version = "1.22.5",
)

gazelle_dependencies()
Expand Down
36 changes: 32 additions & 4 deletions api/nbi/v1alpha/resources/intent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,42 @@ message ModemIntent {
message Beam {
optional BeamTarget target = 1;

optional BeamConfiguration rx = 2;
optional BeamConfiguration tx = 3;
optional RxConfiguration rx = 2;
optional TxConfiguration tx = 3;

// The collection of endpoints served by the beam.
// For example, a collection of user terminals (UTs) served.
//
// Each endpoint is the ID of a network node in Spacetime's network model.
repeated string endpoints = 4;
repeated Endpoint endpoints = 4;
}

message BeamConfiguration {
message RxConfiguration {
optional uint64 center_frequency_hz = 1;
optional uint64 channel_bandwidth_hz = 2;
optional Polarization polarization = 3;

// Symbol rate in Megasymbols per second.
optional double symbol_rate_msps = 5;

optional ModemMode mode = 4;
}

message TxConfiguration {
optional uint64 center_frequency_hz = 1;
optional uint64 channel_bandwidth_hz = 2;
optional Polarization polarization = 3;

// Transmit power in Watts.
optional double power_w = 5;

// Symbol rate in Megasymbols per second.
optional double symbol_rate_msps = 6;

optional ModemMode mode = 4;

// The lowest MODCOD common among all endpoints.
optional string lowest_common_modcod = 7;
}

enum Polarization {
Expand All @@ -234,6 +255,13 @@ enum ModemMode {
MODEM_MODE_DVB_S2X = 2;
}

message Endpoint {
optional string id = 1;
optional string lowest_supported_rx_modcod = 2;
optional double rx_reference_throughput_bps = 3;
optional double tx_reference_throughput_bps = 4;
}

// IntentFailure provides context on the failure of an intent. It's purpose is
// to allow apps to make better decision when faced with failures.
message IntentFailure {
Expand Down
56 changes: 51 additions & 5 deletions api/scheduling/v1alpha/scheduling.proto
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,27 @@ message Beam {

// Parameters specifying the configuration of the beam in the receive
// direction. Absent if the beam is to be used for transmit only.
BeamConfiguration rx = 2;
RxConfiguration rx = 2;

// Parameters specifying the configuration of the beam in the receive
// Parameters specifying the configuration of the beam in the transmit
// direction. Absent if the beam is to be used for receiving only.
BeamConfiguration tx = 3;
TxConfiguration tx = 3;

// The collection of endpoints served by the beam.
// For example, a collection of user terminals (UTs) served.
//
// Each endpoint is the ID of a network node in Spacetime's network model.
repeated string endpoints = 4;
repeated Endpoint endpoints = 4;

// ID of the beam shape.
string shape_id = 5;
}

message BeamTarget {
oneof target {
Ecef ecef = 1;
string ccsds_oem_file_content = 2;
AzEl az_el = 3;
}
}

Expand All @@ -226,13 +230,48 @@ message Ecef {
int64 z_m = 3;
}

message BeamConfiguration {
// An azimuth and elevation angle pair.
//
// The azimuth angle of a vector is the angle between the x-axis and the
// orthogonal projection of the vector onto the xy plane. The angle is positive
// in going from the x axis toward the y axis. The elevation angle is the angle
// between the vector and its orthogonal projection onto the xy-plane.
message AzEl {
// Azimuth, in degrees.
double az_deg = 1;

// Elevation, in degrees.
double el_deg = 2;
}

message RxConfiguration {
uint64 center_frequency_hz = 1;
uint64 channel_bandwidth_hz = 2;
Polarization polarization = 3;

// Symbol rate in Megasymbols per second.
double symbol_rate_msps = 5;

ModemMode mode = 4;
}

message TxConfiguration {
uint64 center_frequency_hz = 1;
uint64 channel_bandwidth_hz = 2;
Polarization polarization = 3;

// Transmit power in Watts.
double power_w = 5;

// Symbol rate in Megasymbols per second.
double symbol_rate_msps = 6;

ModemMode mode = 4;

// The lowest MODCOD common among all endpoints.
string lowest_common_modcod = 7;
}

enum Polarization {
POLARIZATION_UNSPECIFIED = 0;
POLARIZATION_LHCP = 1; // Left-handed circular polarization
Expand All @@ -245,6 +284,13 @@ enum ModemMode {
MODEM_MODE_DVB_S2X = 2;
}

message Endpoint {
string id = 1;
string lowest_supported_rx_modcod = 2;
double rx_reference_throughput_bps = 3;
double tx_reference_throughput_bps = 4;
}

// A Segment Routing Policy Architecture policy description.
// Based in part upon elements from:
// * RFC 9256
Expand Down
91 changes: 24 additions & 67 deletions cdpi_agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"fmt"
"sync"

afpb "aalyria.com/spacetime/api/cdpi/v1alpha"
apipb "aalyria.com/spacetime/api/common"
schedpb "aalyria.com/spacetime/api/scheduling/v1alpha"
"aalyria.com/spacetime/cdpi_agent/enactment"
"aalyria.com/spacetime/cdpi_agent/internal/task"
"aalyria.com/spacetime/cdpi_agent/telemetry"
Expand All @@ -46,7 +43,6 @@ func init() {

var (
errNoClock = errors.New("no clock provided (see WithClock)")
errNoEndpoint = errors.New("no server endpoint provied (see WithServerEndpoint)")
errNoNodes = errors.New("no nodes configured (see WithNode)")
errNoActiveServices = errors.New("no services configured for node (see WithEnactmentBackend and WithTelemetryBackend)")
)
Expand All @@ -71,17 +67,14 @@ func (fn nodeOptFunc) apply(n *node) { fn(n) }
// Agent is a CDPI agent that coordinates change requests across multiple
// nodes.
type Agent struct {
clock clockwork.Clock
nodes map[string]*node
endpoint string
dialOpts []grpc.DialOption
clock clockwork.Clock
nodes map[string]*node
}

// NewAgent creates a new Agent configured with the provided options.
func NewAgent(opts ...AgentOption) (*Agent, error) {
a := &Agent{
nodes: map[string]*node{},
dialOpts: []grpc.DialOption{grpc.WithBlock()},
nodes: map[string]*node{},
}

for _, opt := range opts {
Expand All @@ -96,9 +89,6 @@ func (a *Agent) validate() error {
if a.clock == nil {
errs = append(errs, errNoClock)
}
if a.endpoint == "" {
errs = append(errs, errNoEndpoint)
}
if len(a.nodes) == 0 {
errs = append(errs, errNoNodes)
}
Expand All @@ -122,25 +112,6 @@ func WithRealClock() AgentOption {
return WithClock(clockwork.NewRealClock())
}

// WithServerEndpoint configures the Agent to connect to the provided endpoint.
func WithServerEndpoint(endpoint string) AgentOption {
return agentOptFunc(func(a *Agent) {
a.endpoint = endpoint
})
}

// WithDialOpts configures the Agent to use the provided DialOptions when
// connecting to the CDPI endpoint.
//
// NOTE: The CDPI agent always uses the `grpc.WithBlock` option to ensure
// initial connection errors are caught immediately, whereas logical errors are
// often more tightly scoped to individual RPCs.
func WithDialOpts(dialOpts ...grpc.DialOption) AgentOption {
return agentOptFunc(func(a *Agent) {
a.dialOpts = append(a.dialOpts, dialOpts...)
})
}

// WithNode configures a network node for the agent to represent.
func WithNode(id string, opts ...NodeOption) AgentOption {
n := &node{id: id}
Expand All @@ -153,42 +124,36 @@ func WithNode(id string, opts ...NodeOption) AgentOption {
}

type node struct {
initState *apipb.ControlPlaneState
eb enactment.Backend
tb telemetry.Backend
id string
priority uint32
enactmentsEnabled bool
telemetryEnabled bool
}
ed enactment.Driver
td telemetry.Driver
id string
priority uint32

func WithChannelPriority(priority uint32) NodeOption {
return nodeOptFunc(func(n *node) { n.priority = priority })
enactmentEndpoint, telemetryEndpoint string
enactmentsEnabled, telemetryEnabled bool
enactmentDialOpts, telemetryDialOpts []grpc.DialOption
}

// WithEnactmentBackend configures the EnactmentBackend for the given Node.
func WithEnactmentBackend(eb enactment.Backend) NodeOption {
// WithEnactmentDriver configures the [enactment.Driver] for the given Node.
func WithEnactmentDriver(endpoint string, d enactment.Driver, dialOpts ...grpc.DialOption) NodeOption {
return nodeOptFunc(func(n *node) {
n.eb = eb
n.ed = d
n.enactmentEndpoint = endpoint
n.enactmentDialOpts = dialOpts
n.enactmentsEnabled = true
})
}

// WithTelemetryBackend configures the telemetry.Backend for the given Node.
func WithTelemetryBackend(tb telemetry.Backend) NodeOption {
// WithTelemetryDriver configures the [telemetry.Driver] for the given Node.
func WithTelemetryDriver(endpoint string, d telemetry.Driver, dialOpts ...grpc.DialOption) NodeOption {
return nodeOptFunc(func(n *node) {
n.tb = tb
n.td = d
n.telemetryEndpoint = endpoint
n.telemetryDialOpts = dialOpts
n.telemetryEnabled = true
})
}

// WithInitialState configures the initial state of the Node.
func WithInitialState(initState *apipb.ControlPlaneState) NodeOption {
return nodeOptFunc(func(n *node) {
n.initState = initState
})
}

// Run starts the Agent and blocks until a fatal error is encountered or all
// node controllers terminate.
func (a *Agent) Run(ctx context.Context) error {
Expand Down Expand Up @@ -226,21 +191,13 @@ func (a *Agent) Run(ctx context.Context) error {
}

func (a *Agent) start(ctx context.Context, agentMap *expvar.Map, errCh chan error) error {
log := zerolog.Ctx(ctx)

log.Trace().Str("endpoint", a.endpoint).Msg("contacting the CDPI endpoint")
conn, err := grpc.NewClient(a.endpoint, a.dialOpts...)
if err != nil {
return fmt.Errorf("agent: failed connecting to CDPI backend: %w", err)
}

schedClient := schedpb.NewSchedulingClient(conn)
telemetryClient := afpb.NewNetworkTelemetryStreamingClient(conn)

for _, n := range a.nodes {
ctx, done := context.WithCancel(ctx)

nc := a.newNodeController(n, done, schedClient, telemetryClient)
nc, err := a.newNodeController(n, done)
if err != nil {
return fmt.Errorf("node %q: %w", n.id, err)
}
agentMap.Set(n.id, expvar.Func(nc.Stats))

srv := task.Task(nc.run).
Expand Down
21 changes: 1 addition & 20 deletions cdpi_agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,9 @@ func TestAgentValidation_noOptions(t *testing.T) {
}
}

func TestAgentValidation_onlyClock(t *testing.T) {
t.Parallel()
_, err := NewAgent(WithRealClock())
if !errors.Is(err, errNoEndpoint) {
t.Errorf("expected NewAgent with no endpoint to cause %s, but got %v error instead", errNoEndpoint, err)
}
}

func TestAgentValidation_onlyEndpoint(t *testing.T) {
t.Parallel()
_, err := NewAgent(WithServerEndpoint("dns:///example.com:443"))
if !errors.Is(err, errNoClock) {
t.Errorf("expected NewAgent with no clock to cause %s, but got %v error instead", errNoClock, err)
}
}

func TestAgentValidation_noNodes(t *testing.T) {
t.Parallel()
_, err := NewAgent(
WithServerEndpoint("dns:///example.com:443"),
WithRealClock())
_, err := NewAgent(WithRealClock())

if !errors.Is(err, errNoNodes) {
t.Errorf("expected NewAgent with no nodes to cause %s, but got %v error instead", errNoNodes, err)
Expand All @@ -57,7 +39,6 @@ func TestAgentValidation_noNodes(t *testing.T) {
func TestAgentValidation_noServices(t *testing.T) {
t.Parallel()
_, err := NewAgent(
WithServerEndpoint("dns:///example.com:443"),
WithRealClock(),
WithNode("a"),
WithNode("b"),
Expand Down
5 changes: 1 addition & 4 deletions cdpi_agent/enactment/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ go_library(
name = "enactment",
srcs = ["enactment.go"],
importpath = "aalyria.com/spacetime/cdpi_agent/enactment",
deps = [
"//api/common:common_go_proto",
"//api/scheduling/v1alpha:scheduling_go_grpc",
],
deps = ["//api/scheduling/v1alpha:scheduling_go_grpc"],
)
Loading

0 comments on commit 7a8d580

Please sign in to comment.