Skip to content

Commit

Permalink
apply review comments
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Aug 19, 2024
1 parent 8eb6043 commit 188832f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions pkg/networkservice/ipam/strictipam/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/dualstackippool"
"github.com/networkservicemesh/sdk/pkg/tools/dualstack"
)

type strictIPAMServer struct {
ipPool *dualstackippool.DualStackIPPool
ipPool *dualstack.IPPool
}

// NewServer - returns a new ipam networkservice.NetworkServiceServer that validates the incoming IP context parameters and resets them based on the validation result.
func NewServer(newIPAMServer func(...*net.IPNet) networkservice.NetworkServiceServer, prefixes ...*net.IPNet) networkservice.NetworkServiceServer {
if newIPAMServer == nil {
panic("newIPAMServer should not be nil")
}
var ipPool = dualstackippool.New()
var ipPool = dualstack.New()
for _, p := range prefixes {
ipPool.AddNet(p)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package dualstackippool provides service for managing both ipv4 and ipv6 addresses
package dualstackippool
// Package dualstack provides tools for managing both ipv4 and ipv6 addresses
package dualstack

import (
"net"
Expand All @@ -25,22 +25,22 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/ippool"
)

// DualStackIPPool holds available IPv4 and IPv6 addresses in the structure of red-black tree
type DualStackIPPool struct {
// IPPool holds available IPv4 and IPv6 addresses in the structure of red-black tree
type IPPool struct {
IPv4IPPool *ippool.IPPool
IPv6IPPool *ippool.IPPool
}

// New instantiates a dualstack ip pool as red-black tree
func New() *DualStackIPPool {
pool := new(DualStackIPPool)
func New() *IPPool {
pool := new(IPPool)
pool.IPv4IPPool = ippool.New(net.IPv4len)
pool.IPv6IPPool = ippool.New(net.IPv6len)
return pool
}

// AddNetString - adds ip addresses from network to the pool by string value
func (p *DualStackIPPool) AddNetString(ipNetString string) {
func (p *IPPool) AddNetString(ipNetString string) {
_, ipNet, err := net.ParseCIDR(ipNetString)
if err != nil {
return
Expand All @@ -49,7 +49,7 @@ func (p *DualStackIPPool) AddNetString(ipNetString string) {
}

// AddNet - adds ip addresses from network to the pool
func (p *DualStackIPPool) AddNet(ipNet *net.IPNet) {
func (p *IPPool) AddNet(ipNet *net.IPNet) {
if ipNet.IP.To4() != nil {
p.IPv4IPPool.AddNet(ipNet)
return
Expand All @@ -58,20 +58,20 @@ func (p *DualStackIPPool) AddNet(ipNet *net.IPNet) {
}

// ContainsString parses ip string and checks that pool contains ip
func (p *DualStackIPPool) ContainsString(in string) bool {
func (p *IPPool) ContainsString(in string) bool {
return p.Contains(net.ParseIP(in))
}

// Contains checks that pool contains ip
func (p *DualStackIPPool) Contains(ip net.IP) bool {
func (p *IPPool) Contains(ip net.IP) bool {
if ip.To4() != nil {
return p.IPv4IPPool.Contains(ip)
}
return p.IPv6IPPool.Contains(ip)
}

// PullIPString - returns requested IP address from the pool by string
func (p *DualStackIPPool) PullIPString(in string) (*net.IPNet, error) {
func (p *IPPool) PullIPString(in string) (*net.IPNet, error) {
ip, _, err := net.ParseCIDR(in)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse %s as a CIDR", in)
Expand All @@ -80,7 +80,7 @@ func (p *DualStackIPPool) PullIPString(in string) (*net.IPNet, error) {
}

// PullIP - returns requested IP address from the pool
func (p *DualStackIPPool) PullIP(ip net.IP) (*net.IPNet, error) {
func (p *IPPool) PullIP(ip net.IP) (*net.IPNet, error) {
if ip.To4() != nil {
return p.IPv4IPPool.PullIP(ip)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package dualstackippool
package dualstack

import (
"testing"
Expand Down

0 comments on commit 188832f

Please sign in to comment.