-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new types
FARUpdate
and FARMapUpdate
to handle correctly the …
…update of Forwarding Parameters
- Loading branch information
1 parent
4d6f571
commit c34ba22
Showing
10 changed files
with
225 additions
and
95 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
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,14 @@ | ||
// Copyright Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package api | ||
|
||
import "github.com/wmnsk/go-pfcp/ie" | ||
|
||
type FARMapUpdateInterface interface { | ||
Add(far FARUpdateInterface) error | ||
IntoUpdateFAR() []*ie.IE | ||
Foreach(f func(FARUpdateInterface) error) error | ||
} |
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,15 @@ | ||
// Copyright Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package api | ||
|
||
import "github.com/wmnsk/go-pfcp/ie" | ||
|
||
type FARUpdateInterface interface { | ||
ID() (FARID, error) | ||
ApplyAction() *ie.IE | ||
UpdateForwardingParameters() *ie.IE | ||
NewUpdateFAR() *ie.IE | ||
} |
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,94 @@ | ||
// Copyright Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package pfcp_networking | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"sync" | ||
|
||
"github.com/nextmn/go-pfcp-networking/pfcp/api" | ||
|
||
"github.com/wmnsk/go-pfcp/ie" | ||
) | ||
|
||
type farmapUpdateInternal = map[api.FARID]api.FARUpdateInterface | ||
|
||
type FARMapUpdate struct { | ||
farmap farmapUpdateInternal | ||
mu sync.RWMutex | ||
} | ||
|
||
func NewFARMapUpdate(fars []*ie.IE) (*FARMapUpdate, error, uint8, uint16) { | ||
f := FARMapUpdate{ | ||
farmap: make(farmapUpdateInternal), | ||
mu: sync.RWMutex{}, | ||
} | ||
for _, far := range fars { | ||
id, err := far.FARID() | ||
if err != nil { | ||
switch err { | ||
case io.ErrUnexpectedEOF: | ||
return nil, err, ie.CauseInvalidLength, ie.FARID | ||
case ie.ErrIENotFound: | ||
return nil, err, ie.CauseMandatoryIEMissing, ie.FARID | ||
default: | ||
return nil, err, ie.CauseMandatoryIEIncorrect, ie.CreateFAR | ||
} | ||
} | ||
var ieaa *ie.IE = nil | ||
aa, err := far.ApplyAction() | ||
if err == nil { | ||
ieaa = ie.NewApplyAction(aa...) | ||
} | ||
var iefp *ie.IE = nil | ||
fp, err := far.UpdateForwardingParameters() | ||
if err == nil { | ||
iefp = ie.NewUpdateForwardingParameters(fp...) | ||
} | ||
f.Add(NewFARUpdate(ie.NewFARID(id), ieaa, iefp)) | ||
} | ||
return &f, nil, 0, 0 | ||
|
||
} | ||
|
||
func (m *FARMapUpdate) Add(far api.FARUpdateInterface) error { | ||
id, err := far.ID() | ||
if err != nil { | ||
return err | ||
} | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
if _, exists := m.farmap[id]; exists { | ||
return fmt.Errorf("FAR %d already exists.", id) | ||
} | ||
m.farmap[id] = far | ||
return nil | ||
} | ||
|
||
func (m *FARMapUpdate) IntoUpdateFAR() []*ie.IE { | ||
m.mu.RLock() | ||
defer m.mu.RUnlock() | ||
r := make([]*ie.IE, len(m.farmap)) | ||
|
||
// _ is farID, which is different from index | ||
i := 0 | ||
for _, far := range m.farmap { | ||
r[i] = far.NewUpdateFAR() | ||
i++ | ||
} | ||
return r | ||
} | ||
|
||
func (m *FARMapUpdate) Foreach(f func(api.FARUpdateInterface) error) error { | ||
for _, far := range m.farmap { | ||
err := f(far) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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,50 @@ | ||
// Copyright Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package pfcp_networking | ||
|
||
import ( | ||
"github.com/nextmn/go-pfcp-networking/pfcp/api" | ||
|
||
"github.com/wmnsk/go-pfcp/ie" | ||
) | ||
|
||
type FARUpdate struct { | ||
id *ie.IE | ||
applyAction *ie.IE | ||
updateForwardingParameters *ie.IE | ||
} | ||
|
||
func NewFARUpdate(id *ie.IE, applyAction *ie.IE, updateForwardingParameters *ie.IE) *FARUpdate { | ||
return &FARUpdate{ | ||
id: id, | ||
applyAction: applyAction, | ||
updateForwardingParameters: updateForwardingParameters, | ||
} | ||
} | ||
|
||
func (far *FARUpdate) ID() (api.FARID, error) { | ||
return far.id.FARID() | ||
} | ||
|
||
func (far *FARUpdate) ApplyAction() *ie.IE { | ||
return far.applyAction | ||
} | ||
|
||
func (far *FARUpdate) UpdateForwardingParameters() *ie.IE { | ||
return far.updateForwardingParameters | ||
} | ||
|
||
func (far *FARUpdate) NewUpdateFAR() *ie.IE { | ||
ies := make([]*ie.IE, 0) | ||
ies = append(ies, far.id) | ||
if far.applyAction != nil { | ||
ies = append(ies, far.applyAction) | ||
} | ||
if far.updateForwardingParameters != nil { | ||
ies = append(ies, far.updateForwardingParameters) | ||
} | ||
return ie.NewUpdateFAR(ies...) | ||
} |
Oops, something went wrong.