Skip to content

Commit

Permalink
feat(dp): add carrier aggregation columns (#12899)
Browse files Browse the repository at this point in the history
* feat(dp): add carrier aggregation columns

Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>

* modify CBSD CRUD to include new fields

Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>

* fixes

Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>

* fixes

Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>

Co-authored-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>
  • Loading branch information
WojSad and Wojciech Sadowy committed Jun 24, 2022
1 parent d7d8f10 commit 6e23cf5
Show file tree
Hide file tree
Showing 24 changed files with 755 additions and 277 deletions.
303 changes: 168 additions & 135 deletions dp/cloud/go/protos/cbsd.pb.go

Large diffs are not rendered by default.

105 changes: 80 additions & 25 deletions dp/cloud/go/services/dp/builders/builders.go
Expand Up @@ -44,16 +44,19 @@ type DBCbsdBuilder struct {
func NewDBCbsdBuilder() *DBCbsdBuilder {
return &DBCbsdBuilder{
Cbsd: &storage.DBCbsd{
UserId: db.MakeString(someUserId),
FccId: db.MakeString(someFccId),
CbsdSerialNumber: db.MakeString(someSerialNumber),
PreferredBandwidthMHz: db.MakeInt(20),
PreferredFrequenciesMHz: db.MakeString("[3600]"),
MinPower: db.MakeFloat(10),
MaxPower: db.MakeFloat(20),
NumberOfPorts: db.MakeInt(2),
CbsdCategory: db.MakeString(catB),
SingleStepEnabled: db.MakeBool(false),
UserId: db.MakeString(someUserId),
FccId: db.MakeString(someFccId),
CbsdSerialNumber: db.MakeString(someSerialNumber),
PreferredBandwidthMHz: db.MakeInt(20),
PreferredFrequenciesMHz: db.MakeString("[3600]"),
MinPower: db.MakeFloat(10),
MaxPower: db.MakeFloat(20),
NumberOfPorts: db.MakeInt(2),
CbsdCategory: db.MakeString(catB),
SingleStepEnabled: db.MakeBool(false),
CarrierAggregationEnabled: db.MakeBool(false),
GrantRedundancy: db.MakeBool(true),
MaxIbwMhx: db.MakeInt(150),
},
}
}
Expand Down Expand Up @@ -165,6 +168,21 @@ func (b *DBCbsdBuilder) WithSingleStepEnabled(enabled bool) *DBCbsdBuilder {
return b
}

func (b *DBCbsdBuilder) WithCarrierAggregationEnabled(enabled bool) *DBCbsdBuilder {
b.Cbsd.CarrierAggregationEnabled = db.MakeBool(enabled)
return b
}

func (b *DBCbsdBuilder) WithGrantRedundancy(enabled bool) *DBCbsdBuilder {
b.Cbsd.GrantRedundancy = db.MakeBool(enabled)
return b
}

func (b *DBCbsdBuilder) WithMaxIbwMhx(ibw int64) *DBCbsdBuilder {
b.Cbsd.MaxIbwMhx = db.MakeInt(ibw)
return b
}

func (b *DBCbsdBuilder) WithShouldDeregister(should bool) *DBCbsdBuilder {
b.Cbsd.ShouldDeregister = db.MakeBool(should)
return b
Expand All @@ -185,9 +203,14 @@ func (b *DBCbsdBuilder) WithCbsdCategory(cat string) *DBCbsdBuilder {
return b
}

func (b *DBCbsdBuilder) WithDefaulValues() *DBCbsdBuilder {
return b.WithCbsdCategory(catB).WithSingleStepEnabled(false).WithIndoorDeployment(false)
}
// func (b *DBCbsdBuilder) WithDefaulValues() *DBCbsdBuilder {
// return b.WithCbsdCategory(catB).
// WithSingleStepEnabled(false).
// WithIndoorDeployment(false).
// WithGrantRedundancy(true).
// WithCarrierAggregationEnabled(false).
// WithMaxIbwMhx(150)
// }

type DBGrantBuilder struct {
Grant *storage.DBGrant
Expand Down Expand Up @@ -244,11 +267,14 @@ func NewCbsdProtoPayloadBuilder() *CbsdProtoPayloadBuilder {
MinPower: 10,
MaxPower: 20,
NumberOfAntennas: 2,
MaxIbwMhz: 150,
},
DesiredState: registered,
CbsdCategory: catB,
SingleStepEnabled: false,
InstallationParam: &protos.InstallationParam{},
DesiredState: registered,
CbsdCategory: catB,
SingleStepEnabled: false,
InstallationParam: &protos.InstallationParam{},
CarrierAggregationEnabled: false,
GrantRedundancy: true,
},
}
}
Expand Down Expand Up @@ -446,6 +472,7 @@ func NewCbsdModelPayloadBuilder() *CbsdModelPayloadBuilder {
MaxPower: to_pointer.Float(20),
MinPower: to_pointer.Float(10),
NumberOfAntennas: 2,
MaxIbwMhz: 150,
},
SingleStepEnabled: false,
CbsdCategory: catB,
Expand All @@ -454,11 +481,13 @@ func NewCbsdModelPayloadBuilder() *CbsdModelPayloadBuilder {
BandwidthMhz: 20,
FrequenciesMhz: []int64{3600},
},
FccID: someFccId,
SerialNumber: someSerialNumber,
UserID: someUserId,
CbsdID: someCbsdId,
State: registered,
FccID: someFccId,
SerialNumber: someSerialNumber,
UserID: someUserId,
CbsdID: someCbsdId,
State: registered,
CarrierAggregationEnabled: false,
GrantRedundancy: true,
}}
}

Expand Down Expand Up @@ -501,10 +530,13 @@ func NewMutableCbsdModelPayloadBuilder() *MutableCbsdModelBuilder {
MaxPower: to_pointer.Float(20),
MinPower: to_pointer.Float(10),
NumberOfAntennas: 2,
MaxIbwMhz: 150,
},
DesiredState: registered,
SingleStepEnabled: to_pointer.Bool(false),
CbsdCategory: catB,
DesiredState: registered,
SingleStepEnabled: to_pointer.Bool(false),
CarrierAggregationEnabled: to_pointer.Bool(false),
GrantRedundancy: to_pointer.Bool(true),
CbsdCategory: catB,
FrequencyPreferences: models.FrequencyPreferences{
BandwidthMhz: 20,
FrequenciesMhz: []int64{3600},
Expand Down Expand Up @@ -560,6 +592,11 @@ func (b *MutableCbsdModelBuilder) WithNumberOfAntennas(number int64) *MutableCbs
return b
}

func (b *MutableCbsdModelBuilder) WithMaxIbwMhz(number int64) *MutableCbsdModelBuilder {
b.Payload.Capabilities.MaxIbwMhz = number
return b
}

func (b *MutableCbsdModelBuilder) WithSingleStepEnabled(enabled *bool) *MutableCbsdModelBuilder {
if enabled == nil {
b.Payload.SingleStepEnabled = nil
Expand All @@ -569,6 +606,24 @@ func (b *MutableCbsdModelBuilder) WithSingleStepEnabled(enabled *bool) *MutableC
return b
}

func (b *MutableCbsdModelBuilder) WithCarrierAggregationEnabled(enabled *bool) *MutableCbsdModelBuilder {
if enabled == nil {
b.Payload.CarrierAggregationEnabled = nil
} else {
b.Payload.CarrierAggregationEnabled = to_pointer.Bool(*enabled)
}
return b
}

func (b *MutableCbsdModelBuilder) WithGrantRedundancy(enabled *bool) *MutableCbsdModelBuilder {
if enabled == nil {
b.Payload.GrantRedundancy = nil
} else {
b.Payload.GrantRedundancy = to_pointer.Bool(*enabled)
}
return b
}

func (b *MutableCbsdModelBuilder) WithMinPower(power *float64) *MutableCbsdModelBuilder {
if power == nil {
b.Payload.Capabilities.MinPower = nil
Expand Down
14 changes: 10 additions & 4 deletions dp/cloud/go/services/dp/obsidian/cbsd/handlers.go
Expand Up @@ -139,16 +139,19 @@ func createCbsd(c echo.Context) error {
if err := c.Bind(payload); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
if err := payload.Validate(strfmt.Default); err != nil {
ctx := c.Request().Context()
if err := payload.ValidateModel(ctx); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
client, err := getCbsdManagerClient()
if err != nil {
return err
}
data := models.CbsdToBackend(payload)
data, err := models.CbsdToBackend(payload)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
req := protos.CreateCbsdRequest{NetworkId: networkId, Data: data}
ctx := c.Request().Context()
_, err = client.CreateCbsd(ctx, &req)
if err != nil {
return getHttpError(err)
Expand Down Expand Up @@ -206,7 +209,10 @@ func updateCbsd(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusNotFound, err)
}
data := models.CbsdToBackend(payload)
data, err := models.CbsdToBackend(payload)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
req := protos.UpdateCbsdRequest{NetworkId: networkId, Id: int64(id), Data: data}
ctx := c.Request().Context()
_, ierr := client.UserUpdateCbsd(ctx, &req)
Expand Down
35 changes: 30 additions & 5 deletions dp/cloud/go/services/dp/obsidian/cbsd/handlers_test.go
Expand Up @@ -33,6 +33,7 @@ import (
b "magma/dp/cloud/go/services/dp/builders"
"magma/dp/cloud/go/services/dp/obsidian/cbsd"
"magma/dp/cloud/go/services/dp/obsidian/models"
"magma/dp/cloud/go/services/dp/obsidian/to_pointer"
"magma/dp/cloud/go/services/dp/storage/db"
"magma/orc8r/cloud/go/obsidian"
"magma/orc8r/cloud/go/obsidian/tests"
Expand Down Expand Up @@ -238,17 +239,38 @@ func (s *HandlersTestSuite) TestCreateCbsd() {
name string
inputPayload *models.MutableCbsd
expectedPayload *protos.CbsdData
expectedStatus int
expectedError string
}{{
name: "test create without installation param",
inputPayload: b.NewMutableCbsdModelPayloadBuilder().Payload,
expectedPayload: b.NewCbsdProtoPayloadBuilder().Payload,
expectedStatus: http.StatusCreated,
expectedError: "",
}, {
name: "test create with antenna gain",
inputPayload: b.NewMutableCbsdModelPayloadBuilder().
WithAntennaGain(10.5).Payload,
expectedPayload: b.NewCbsdProtoPayloadBuilder().
WithEmptyInstallationParam().
WithAntennaGain(10.5).Payload,
expectedStatus: http.StatusCreated,
expectedError: "",
}, {
name: "test create with carrier aggregation is enabled and grant_redundancy is false",
inputPayload: b.NewMutableCbsdModelPayloadBuilder().
WithGrantRedundancy(to_pointer.Bool(false)).
WithCarrierAggregationEnabled(to_pointer.Bool(true)).
Payload,
expectedStatus: http.StatusBadRequest,
expectedError: "grant_redundancy cannot be set to false when carrier_aggregation_enabled is enabled",
}, {
name: "test failed model validation raises 400",
inputPayload: b.NewMutableCbsdModelPayloadBuilder().
WithSingleStepEnabled(nil).
Payload,
expectedStatus: http.StatusBadRequest,
expectedError: "single_step_enabled in body is required",
}}
for _, tc := range testCases {
s.Run(tc.name, func() {
Expand All @@ -268,22 +290,24 @@ func (s *HandlersTestSuite) TestCreateCbsd() {
ParamNames: []string{"network_id"},
ParamValues: []string{"n1"},
Handler: createCbsd,
ExpectedStatus: http.StatusCreated,
ExpectedStatus: tc.expectedStatus,
ExpectedError: tc.expectedError,
}
tests.RunUnitTest(s.T(), e, tc)
})
}
}

func (s *HandlersTestSuite) TestCreateWithDuplicateUniqueFieldsReturnsConflict() {
const errMsg = "some error"
e := echo.New()
obsidianHandlers := cbsd.GetHandlers()
payload := b.NewMutableCbsdModelPayloadBuilder().Payload
const errMsg = "some error"
data, _ := models.CbsdToBackend(payload)
s.cbsdServer.err = status.Error(codes.AlreadyExists, errMsg)
s.cbsdServer.expectedCreateRequest = &protos.CreateCbsdRequest{
NetworkId: "n1",
Data: models.CbsdToBackend(payload),
Data: data,
}
createCbsd := tests.GetHandlerByPathAndMethod(s.T(), obsidianHandlers, cbsd.ManageCbsdsPath, obsidian.POST).HandlerFunc
tc := tests.Test{
Expand Down Expand Up @@ -339,9 +363,9 @@ func (s *HandlersTestSuite) TestDeleteCbsd() {
}

func (s *HandlersTestSuite) TestDeleteNonexistentCbsd() {
const errorMsg = "some msg"
e := echo.New()
obsidianHandlers := cbsd.GetHandlers()
const errorMsg = "some msg"
s.cbsdServer.err = status.Error(codes.NotFound, errorMsg)
s.cbsdServer.expectedDeleteRequest = &protos.DeleteCbsdRequest{
NetworkId: "n1",
Expand Down Expand Up @@ -431,11 +455,12 @@ func (s *HandlersTestSuite) TestUpdateCbsdWithDuplicateUniqueFieldsReturnsConfli
obsidianHandlers := cbsd.GetHandlers()
payload := b.NewMutableCbsdModelPayloadBuilder().Payload
const errMsg = "some error"
data, _ := models.CbsdToBackend(payload)
s.cbsdServer.err = status.Error(codes.AlreadyExists, errMsg)
s.cbsdServer.expectedUpdateRequest = &protos.UpdateCbsdRequest{
NetworkId: "n1",
Id: 1,
Data: models.CbsdToBackend(payload),
Data: data,
}
updateCbsd := tests.GetHandlerByPathAndMethod(s.T(), obsidianHandlers, cbsd.ManageCbsdPath, obsidian.PUT).HandlerFunc
tc := tests.Test{
Expand Down
17 changes: 17 additions & 0 deletions dp/cloud/go/services/dp/obsidian/models/capabilities_swaggergen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e23cf5

Please sign in to comment.