Skip to content

Commit

Permalink
Merge pull request #3620 from jcaamano/ic-l2-ip-allocator
Browse files Browse the repository at this point in the history
Enable interconnect for localnet topology
  • Loading branch information
trozet committed Jul 10, 2023
2 parents 5d6b136 + 7821862 commit c57f309
Show file tree
Hide file tree
Showing 60 changed files with 3,675 additions and 1,693 deletions.
2 changes: 1 addition & 1 deletion go-controller/hack/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function testrun {
echo "Increasing timeout to 20m for package ${pkg}"
args="${args} -test.timeout=20m"
fi
if grep -q -r "ginkgo" ."${path}"; then
if grep -q "ginkgo" ."${path}"/*_test.go; then
prefix=$(echo "${path}" | cut -c 2- | sed 's,/,_,g')
ginkgoargs="-ginkgo.v ${ginkgo_focus} -ginkgo.reportFile ${TEST_REPORT_DIR}/junit-${prefix}.xml"
fi
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 allocator
package bitmap

import (
"errors"
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 allocator
package bitmap

import (
"testing"
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 allocator
package bitmap

// Interface manages the allocation of items out of a range. Interface
// should be threadsafe.
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 allocator
package bitmap

import "math/big"

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 allocator
package bitmap

import (
"math/big"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package ipallocator
package ip

import (
"errors"
"fmt"
"math/big"
"net"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/ovn/ipallocator/allocator"
allocator "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/allocator/bitmap"
utilnet "k8s.io/utils/net"
)

Expand All @@ -35,13 +35,19 @@ type Interface interface {
ForEach(func(net.IP))
CIDR() net.IPNet
Has(ip net.IP) bool
Reserved(ip net.IP) bool
}

var (
ErrFull = errors.New("range is full")
ErrAllocated = errors.New("provided IP is already allocated")
)

// IsErrAllocated returns true if err is of type ErrAllocated
func IsErrAllocated(err error) bool {
return errors.Is(err, ErrAllocated)
}

type ErrNotInRange struct {
ValidRange string
}
Expand Down Expand Up @@ -199,6 +205,17 @@ func (r *Range) Has(ip net.IP) bool {
return r.alloc.Has(offset)
}

// Reserved returns true if the provided IP can't be allocated. This is *only*
// true for the network and broadcast addresses.
func (r *Range) Reserved(ip net.IP) bool {
if !r.net.Contains(ip) {
return false
}

offset := calculateIPOffset(r.base, ip)
return offset == -1 || offset == r.max
}

// contains returns true and the offset if the ip is in the range, and false
// and nil otherwise. The first and last addresses of the CIDR are omitted.
func (r *Range) contains(ip net.IP) (bool, int) {
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 ipallocator
package ip

import (
"net"
Expand Down Expand Up @@ -258,3 +258,30 @@ func TestForEach(t *testing.T) {
}
}
}

func TestReserved(t *testing.T) {
_, cidr, err := net.ParseCIDR("192.168.1.0/24")
if err != nil {
t.Fatal(err)
}
r, err := NewCIDRRange(cidr)
if err != nil {
t.Fatal(err)
}

if !r.Reserved(net.ParseIP("192.168.1.0")) {
t.Errorf("should be a reserved address: %s", "192.168.1.0")
}

if !r.Reserved(net.ParseIP("192.168.1.255")) {
t.Errorf("should be a reserved address: %s", "192.168.1.255")
}

if r.Reserved(net.ParseIP("192.168.1.1")) {
t.Errorf("should not be a reserved address: %s", "192.168.1.1")
}

if r.Reserved(net.ParseIP("192.168.1.254")) {
t.Errorf("should not be a reserved address: %s", "192.168.1.254")
}
}
Loading

0 comments on commit c57f309

Please sign in to comment.