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:
@@ -76,6 +76,21 @@ func RingOneAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr,
|
|||||||
return addr, err
|
return addr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 := unsafeRingThreeAddress(region, 0)
|
||||||
|
subnet = netip.PrefixFrom(addr, RingThreeBits)
|
||||||
|
}
|
||||||
|
return subnet, err
|
||||||
|
}
|
||||||
|
|
||||||
func unsafeRingZeroAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr {
|
func unsafeRingZeroAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr {
|
||||||
r := uint(region)
|
r := uint(region)
|
||||||
z := uint(zone)
|
z := uint(zone)
|
||||||
@@ -93,3 +108,13 @@ func unsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr
|
|||||||
|
|
||||||
return AddrFrom4(10, r, z<<4+n1, n0)
|
return AddrFrom4(10, r, z<<4+n1, n0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unsafeRingThreeAddress(region RegionID, n uint) netip.Addr {
|
||||||
|
r := uint(region)
|
||||||
|
|
||||||
|
n2 := n >> 16
|
||||||
|
n1 := n >> 8
|
||||||
|
n0 := n >> 0
|
||||||
|
|
||||||
|
return AddrFrom4(10, r<<4+n2, n1, n0)
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ const (
|
|||||||
RingZeroBits = 16
|
RingZeroBits = 16
|
||||||
// RingOneBits indicates the size of the prefix on the ring 1 (lan) network.
|
// RingOneBits indicates the size of the prefix on the ring 1 (lan) network.
|
||||||
RingOneBits = 20
|
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].
|
// RegionID is the identifier of a region, valid between 1 and [RegionMax].
|
||||||
|
|||||||
Reference in New Issue
Block a user