-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Badhrinath Pa
authored and
badhri85
committed
Feb 2, 2021
1 parent
44f27a2
commit e6c0bf4
Showing
14 changed files
with
198 additions
and
74 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
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,55 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright(c) 2020 Intel Corporation | ||
|
||
package main | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
"net" | ||
|
||
"github.com/wmnsk/go-pfcp/ie" | ||
) | ||
|
||
type ip_pool struct { | ||
free_pool []string | ||
} | ||
|
||
func needAllocIp(ueIPaddr *ie.UEIPAddressFields) bool { | ||
if has2ndBit(ueIPaddr.Flags) && !has5thBit(ueIPaddr.Flags) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func (ipp *ip_pool) deallocIPV4(element net.IP) { | ||
ipp.free_pool = append(ipp.free_pool, element.String()) // Simply append to enqueue. | ||
log.Println("Enqueued:", element.String()) | ||
} | ||
|
||
func (ipp *ip_pool) allocIPV4() (net.IP, error) { | ||
if len(ipp.free_pool) == 0 { | ||
err := errors.New("ip pool empty") | ||
return nil, err | ||
} | ||
element := ipp.free_pool[0] // The first element is the one to be dequeued. | ||
log.Println("Dequeued:", element) | ||
ipp.free_pool = ipp.free_pool[1:] // Slice off the element once it is dequeued. | ||
ipVal := net.ParseIP(element).To4() | ||
return ipVal, nil | ||
} | ||
|
||
func (ipp *ip_pool) init_pool(cidr string) error { | ||
ip, ipnet, err := net.ParseCIDR(cidr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) { | ||
ipp.free_pool = append(ipp.free_pool, ip.String()) | ||
} | ||
// remove network address and broadcast address | ||
|
||
ipp.free_pool = ipp.free_pool[1 : len(ipp.free_pool)-1] | ||
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
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
Oops, something went wrong.