rings: RingThreePrefix()

Ring 3 corresponds to the pods of the kubernetes cluster of a region

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2024-05-25 21:26:35 +00:00
parent dd22c8f72a
commit 57251ce0af
2 changed files with 21 additions and 0 deletions
+3
View File
@@ -23,6 +23,9 @@ const (
RingZeroBits = 16
// RingOneBits indicates the size of the prefix on the ring 1 (lan) network.
RingOneBits = 20
// RingThreeBits indicates the size of the prefix on the ring 3 (pods) network
// of the kubernetes cluster of a region.
RingThreeBits = 12
)
// RegionID is the identifier of a region, valid between 1 and [RegionMax].
+18
View File
@@ -0,0 +1,18 @@
package rings
import "net/netip"
// RingThreePrefix returns the subnet corresponding to
// the pods of a cluster.
//
// Ring 3 is a `10.(region_id << 4).0.0/12` network
func RingThreePrefix(region RegionID) (subnet netip.Prefix, err error) {
switch {
case !region.Valid():
err = ErrOutOfRange(region, "region")
default:
addr := AddrFrom4(10, uint(region)<<4, 0, 0)
subnet = netip.PrefixFrom(addr, RingThreeBits)
}
return subnet, err
}