Skip to content

Commit

Permalink
feat(dp): Add carrier aggregation logic to AMC (#13379)
Browse files Browse the repository at this point in the history
Signed-off-by: Kuba Marciniszyn <kuba@freedomfi.com>
  • Loading branch information
jkmar committed Jul 25, 2022
1 parent c2dd72d commit 1b7a055
Show file tree
Hide file tree
Showing 38 changed files with 957 additions and 2,029 deletions.
7 changes: 3 additions & 4 deletions dp/cloud/go/active_mode_controller/internal/app/app.go
Expand Up @@ -24,15 +24,14 @@ import (

"magma/dp/cloud/go/active_mode_controller/config"
"magma/dp/cloud/go/active_mode_controller/internal/message_generator"
"magma/dp/cloud/go/active_mode_controller/internal/message_generator/sas"
"magma/dp/cloud/go/active_mode_controller/protos/active_mode"
"magma/dp/cloud/go/active_mode_controller/protos/requests"
)

type App struct {
additionalGrpcOpts []grpc.DialOption
clock Clock
rng sas.RNG
rng message_generator.RNG
cfg *config.Config
}

Expand All @@ -59,7 +58,7 @@ func WithDialer(dialer Dialer) Option {
}
}

func WithRNG(rng sas.RNG) Option {
func WithRNG(rng message_generator.RNG) Option {
return func(a *App) {
a.rng = rng
}
Expand Down Expand Up @@ -110,7 +109,7 @@ func (a *App) Run(ctx context.Context) error {
}
}

func newGenerator(cfg *config.Config, rng sas.RNG) messageGenerator {
func newGenerator(cfg *config.Config, rng message_generator.RNG) messageGenerator {
return message_generator.NewMessageGenerator(
cfg.HeartbeatSendTimeout+cfg.PollingInterval+cfg.RequestProcessingInterval,
cfg.CbsdInactivityTimeout,
Expand Down
47 changes: 19 additions & 28 deletions dp/cloud/go/active_mode_controller/internal/app/app_test.go
Expand Up @@ -28,6 +28,7 @@ import (

"magma/dp/cloud/go/active_mode_controller/config"
"magma/dp/cloud/go/active_mode_controller/internal/app"
"magma/dp/cloud/go/active_mode_controller/internal/test_utils/builders"
"magma/dp/cloud/go/active_mode_controller/protos/active_mode"
"magma/dp/cloud/go/active_mode_controller/protos/requests"
)
Expand All @@ -37,7 +38,6 @@ const (
timeout = time.Millisecond * 50
heartbeatTimeout = time.Second * 10
pollingTimeout = time.Second * 20
currentTime = 10000
)

func TestAppTestSuite(t *testing.T) {
Expand Down Expand Up @@ -84,18 +84,16 @@ func (s *AppTestSuite) TestGetStateAndSendRequests() {
s.thenRequestsWereEventuallyReceived(getExpectedRequests("some"))
}

// TODO cleanup this
func (s *AppTestSuite) TestCalculateHeartbeatDeadline() {
const interval = 50 * time.Second
const delta = heartbeatTimeout + pollingTimeout
now := s.clock.Now()
base := now.Add(delta - interval)
timestamps := []time.Time{
base.Add(2 * time.Second), base.Add(time.Second),
base, base.Add(-time.Second),
}
timestamps := []time.Time{base.Add(time.Second), base}
s.givenState(buildStateWithAuthorizedGrants("some", interval, timestamps...))
s.whenTickerFired()
s.thenRequestsWereEventuallyReceived(getExpectedHeartbeatRequests("some", "2", "3"))
s.thenRequestsWereEventuallyReceived(getExpectedHeartbeatRequests("some", "1"))
}

func (s *AppTestSuite) TestAppWorkInALoop() {
Expand Down Expand Up @@ -220,38 +218,31 @@ func (s *AppTestSuite) thenNoOtherRequestWasReceived() {
func buildSomeState(names ...string) *active_mode.State {
cbsds := make([]*active_mode.Cbsd, len(names))
for i, name := range names {
cbsds[i] = &active_mode.Cbsd{
DesiredState: active_mode.CbsdState_Registered,
SasSettings: &active_mode.SasSettings{
UserId: name,
FccId: name,
SerialNumber: name,
},
State: active_mode.CbsdState_Unregistered,
LastSeenTimestamp: currentTime,
}
cbsds[i] = builders.NewCbsdBuilder().
WithState(active_mode.CbsdState_Unregistered).
WithName(name).
Build()
}
return &active_mode.State{Cbsds: cbsds}
}

func buildStateWithAuthorizedGrants(name string, interval time.Duration, timestamps ...time.Time) *active_mode.State {
grants := make([]*active_mode.Grant, len(timestamps))
b := builders.NewCbsdBuilder().
WithName(name).
WithChannel(builders.SomeChannel).
WithAvailableFrequencies(builders.NoAvailableFrequencies).
WithCarrierAggregation()
for i, timestamp := range timestamps {
grants[i] = &active_mode.Grant{
b.WithGrant(&active_mode.Grant{
Id: fmt.Sprintf("%d", i),
State: active_mode.GrantState_Authorized,
HeartbeatIntervalSec: int64(interval / time.Second),
LastHeartbeatTimestamp: timestamp.Unix(),
}
LowFrequencyHz: int64(3550+10*i) * 1e6,
HighFrequencyHz: int64(3550+10*(i+1)) * 1e6,
})
}
cbsds := []*active_mode.Cbsd{{
DesiredState: active_mode.CbsdState_Registered,
CbsdId: name,
State: active_mode.CbsdState_Registered,
Grants: grants,
LastSeenTimestamp: currentTime,
}}
return &active_mode.State{Cbsds: cbsds}
return &active_mode.State{Cbsds: []*active_mode.Cbsd{b.Build()}}
}

func getExpectedRequests(name string) []*requests.RequestPayload {
Expand Down Expand Up @@ -294,7 +285,7 @@ type stubClock struct {
}

func (s *stubClock) Now() time.Time {
return time.Unix(currentTime, 0)
return time.Unix(builders.Now, 0)
}

func (s *stubClock) Tick(_ time.Duration) *time.Ticker {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,59 @@
/*
Copyright 2022 The Magma Authors.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package message

import (
"context"
"strconv"
"strings"

"magma/dp/cloud/go/active_mode_controller/protos/active_mode"
)

func NewStoreAvailableFrequenciesMessage(id int64, frequencies []uint32) *storeAvailableFrequenciesMessage {
return &storeAvailableFrequenciesMessage{
id: id,
frequencies: frequencies,
}
}

type storeAvailableFrequenciesMessage struct {
id int64
frequencies []uint32
}

func (s *storeAvailableFrequenciesMessage) Send(ctx context.Context, provider ClientProvider) error {
req := &active_mode.StoreAvailableFrequenciesRequest{
Id: s.id,
AvailableFrequencies: s.frequencies,
}
client := provider.GetActiveModeClient()
_, err := client.StoreAvailableFrequencies(ctx, req)
return err
}

func (s *storeAvailableFrequenciesMessage) String() string {
b := strings.Builder{}
_, _ = b.WriteString("store available frequencies: ")
_, _ = b.WriteString(strconv.FormatInt(s.id, 10))
_, _ = b.WriteString(" (")
for i, f := range s.frequencies {
_, _ = b.WriteString(strconv.FormatUint(uint64(f), 2))
if i != len(s.frequencies)-1 {
_, _ = b.WriteString(", ")
}
}
_, _ = b.WriteString(")")
return b.String()
}

0 comments on commit 1b7a055

Please sign in to comment.