Skip to content

Commit

Permalink
Merge pull request #5 from bgp/rename_roa_to_vrp
Browse files Browse the repository at this point in the history
Utilize "VRP" terminology instead of "ROA" to be more concise.
  • Loading branch information
randomthingsandstuff authored May 11, 2021
2 parents 712c5bc + 0bbe564 commit f384479
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 351 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ INFO[0001] Slurm filtering: 112214 kept, 159 removed, 1 asserted
INFO[0002] New update (112215 uniques, 112215 total prefixes).
```

For instance, if the original JSON fetched contains the ROA: `10.0.0.0/24-24 AS65001`,
For instance, if the original JSON fetched contains the VRP: `10.0.0.0/24-24 AS65001`,
it will be removed.

The JSON exported by StayRTR will contain the overrides and the file can be signed again.
Others StayRTR can be configured to fetch the ROAs from the filtering StayRTR:
Others StayRTR can be configured to fetch the VRPs from the filtering StayRTR:
the operator manages one SLURM file on a leader StayRTR.

## Debug the content
Expand Down Expand Up @@ -483,7 +483,7 @@ router bgp <asn>
```
If multiple caches are configured, the preference controls the priority.
Caches which are more preferred will be connected to first, if they are not reachable then connections will be attempted to less preferred caches.
If caches have the same preference value, they will all be connected to and the ROAs that are synced from them will be merged together.
If caches have the same preference value, they will all be connected to and the VRPs that are synced from them will be merged together.

To visualize the state of the session:

Expand Down
10 changes: 5 additions & 5 deletions cmd/rtrdump/rtrdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var (
)

type Client struct {
Data prefixfile.ROAList
Data prefixfile.VRPList

InitSerial bool
Serial uint32
Expand All @@ -78,7 +78,7 @@ type Client struct {
func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
switch pdu := pdu.(type) {
case *rtr.PDUIPv4Prefix:
rj := prefixfile.ROAJson{
rj := prefixfile.VRPJson{
Prefix: pdu.Prefix.String(),
ASN: fmt.Sprintf("AS%v", pdu.ASN),
Length: pdu.MaxLen,
Expand All @@ -90,7 +90,7 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
log.Debugf("Received: %v", pdu)
}
case *rtr.PDUIPv6Prefix:
rj := prefixfile.ROAJson{
rj := prefixfile.VRPJson{
Prefix: pdu.Prefix.String(),
ASN: fmt.Sprintf("AS%v", pdu.ASN),
Length: pdu.MaxLen,
Expand Down Expand Up @@ -146,9 +146,9 @@ func main() {
}

client := &Client{
Data: prefixfile.ROAList{
Data: prefixfile.VRPList{
Metadata: prefixfile.MetaData{},
Data: make([]prefixfile.ROAJson, 0),
Data: make([]prefixfile.VRPJson, 0),
},
InitSerial: *InitSerial,
Serial: uint32(*Serial),
Expand Down
108 changes: 54 additions & 54 deletions cmd/rtrmon/rtrmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ var (
"key": METHOD_KEY,
}

ROACount = prometheus.NewGaugeVec(
VRPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "rpki_roas",
Help: "Total number of ROAS/amount of differents.",
Name: "rpki_vrps",
Help: "Total number of VRPS/amount of differents.",
},
[]string{"server", "url", "type"},
)
Expand Down Expand Up @@ -125,20 +125,20 @@ var (
)

func init() {
prometheus.MustRegister(ROACount)
prometheus.MustRegister(VRPCount)
prometheus.MustRegister(RTRState)
prometheus.MustRegister(RTRSerial)
prometheus.MustRegister(RTRSession)
prometheus.MustRegister(LastUpdate)
}

func decodeJSON(data []byte) (*prefixfile.ROAList, error) {
func decodeJSON(data []byte) (*prefixfile.VRPList, error) {
buf := bytes.NewBuffer(data)
dec := json.NewDecoder(buf)

var roalistjson prefixfile.ROAList
err := dec.Decode(&roalistjson)
return &roalistjson, err
var vrplistjson prefixfile.VRPList
err := dec.Decode(&vrplistjson)
return &vrplistjson, err
}

type Client struct {
Expand All @@ -164,9 +164,9 @@ type Client struct {
lastUpdate time.Time

compLock *sync.RWMutex
roas map[string]*ROAJsonSimple
vrps map[string]*VRPJsonSimple
compRtrLock *sync.RWMutex
roasRtr map[string]*ROAJsonSimple
vrpsRtr map[string]*VRPJsonSimple

unlock chan bool
ch chan int
Expand All @@ -180,9 +180,9 @@ type Client struct {
func NewClient() *Client {
return &Client{
compLock: &sync.RWMutex{},
roas: make(map[string]*ROAJsonSimple),
vrps: make(map[string]*VRPJsonSimple),
compRtrLock: &sync.RWMutex{},
roasRtr: make(map[string]*ROAJsonSimple),
vrpsRtr: make(map[string]*VRPJsonSimple),
}
}

Expand Down Expand Up @@ -278,31 +278,31 @@ func (c *Client) Start(id int, ch chan int) {

c.lastUpdate = time.Now().UTC()

tmpRoaMap := make(map[string]*ROAJsonSimple)
for _, roa := range decoded.Data {
asn, err := roa.GetASN2()
tmpVrpMap := make(map[string]*VRPJsonSimple)
for _, vrp := range decoded.Data {
asn, err := vrp.GetASN2()
if err != nil {
log.Errorf("%d: exploration error for %v asn: %v", id, roa, err)
log.Errorf("%d: exploration error for %v asn: %v", id, vrp, err)
continue
}
prefix, err := roa.GetPrefix2()
prefix, err := vrp.GetPrefix2()
if err != nil {
log.Errorf("%d: exploration error for %v prefix: %v", id, roa, err)
log.Errorf("%d: exploration error for %v prefix: %v", id, vrp, err)
continue
}

maxlen := roa.GetMaxLen()
maxlen := vrp.GetMaxLen()
key := fmt.Sprintf("%s-%d-%d", prefix.String(), maxlen, asn)

roaSimple := ROAJsonSimple{
vrpSimple := VRPJsonSimple{
Prefix: prefix.String(),
ASN: asn,
Length: uint8(maxlen),
}
tmpRoaMap[key] = &roaSimple
tmpVrpMap[key] = &vrpSimple
}
c.compLock.Lock()
c.roas = tmpRoaMap
c.vrps = tmpVrpMap
c.lastUpdate = time.Now().UTC()
c.serial = uint32(decoded.Metadata.Serial)
c.compLock.Unlock()
Expand All @@ -318,7 +318,7 @@ func (c *Client) Start(id int, ch chan int) {
func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
switch pdu := pdu.(type) {
case *rtr.PDUIPv4Prefix:
roa := ROAJsonSimple{
vrp := VRPJsonSimple{
Prefix: pdu.Prefix.String(),
ASN: pdu.ASN,
Length: pdu.MaxLen,
Expand All @@ -328,14 +328,14 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
c.compRtrLock.Lock()

if pdu.Flags == rtr.FLAG_ADDED {
c.roasRtr[key] = &roa
c.vrpsRtr[key] = &vrp
} else {
delete(c.roasRtr, key)
delete(c.vrpsRtr, key)
}

c.compRtrLock.Unlock()
case *rtr.PDUIPv6Prefix:
roa := ROAJsonSimple{
vrp := VRPJsonSimple{
Prefix: pdu.Prefix.String(),
ASN: pdu.ASN,
Length: pdu.MaxLen,
Expand All @@ -345,9 +345,9 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
c.compRtrLock.Lock()

if pdu.Flags == rtr.FLAG_ADDED {
c.roasRtr[key] = &roa
c.vrpsRtr[key] = &vrp
} else {
delete(c.roasRtr, key)
delete(c.vrpsRtr, key)
}

c.compRtrLock.Unlock()
Expand All @@ -356,14 +356,14 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {

c.compRtrLock.Lock()
c.serial = pdu.SerialNumber
tmpRoaMap := make(map[string]*ROAJsonSimple, len(c.roasRtr))
for key, roa := range c.roasRtr {
tmpRoaMap[key] = roa
tmpVrpMap := make(map[string]*VRPJsonSimple, len(c.vrpsRtr))
for key, vrp := range c.vrpsRtr {
tmpVrpMap[key] = vrp
}
c.compRtrLock.Unlock()

c.compLock.Lock()
c.roas = tmpRoaMap
c.vrps = tmpVrpMap

c.rtrRefresh = pdu.RefreshInterval
c.rtrRetry = pdu.RetryInterval
Expand Down Expand Up @@ -437,15 +437,15 @@ func (c *Client) continuousRTR(cs *rtr.ClientSession) {
}
}

func (c *Client) GetData() (map[string]*ROAJsonSimple, *diffMetadata) {
func (c *Client) GetData() (map[string]*VRPJsonSimple, *diffMetadata) {
c.compLock.RLock()
roas := c.roas
vrps := c.vrps

md := &diffMetadata{
URL: c.Path,
Serial: c.serial,
SessionID: c.sessionID,
Count: len(roas),
Count: len(vrps),

RTRRefresh: c.rtrRefresh,
RTRRetry: c.rtrRetry,
Expand All @@ -456,7 +456,7 @@ func (c *Client) GetData() (map[string]*ROAJsonSimple, *diffMetadata) {

c.compLock.RUnlock()

return roas, md
return vrps, md
}

type Comparator struct {
Expand All @@ -468,7 +468,7 @@ type Comparator struct {
OneOff bool

diffLock *sync.RWMutex
onlyIn1, onlyIn2 []*ROAJsonSimple
onlyIn1, onlyIn2 []*VRPJsonSimple
md1 *diffMetadata
md2 *diffMetadata
}
Expand All @@ -485,11 +485,11 @@ func NewComparator(c1, c2 *Client) *Comparator {
}
}

func Diff(a, b map[string]*ROAJsonSimple) []*ROAJsonSimple {
onlyInA := make([]*ROAJsonSimple, 0)
for key, roa := range a {
func Diff(a, b map[string]*VRPJsonSimple) []*VRPJsonSimple {
onlyInA := make([]*VRPJsonSimple, 0)
for key, vrp := range a {
if _, ok := b[key]; !ok {
onlyInA = append(onlyInA, roa)
onlyInA = append(onlyInA, vrp)
}
}
return onlyInA
Expand All @@ -507,7 +507,7 @@ type diffMetadata struct {
RTRExpire uint32 `json:"rtr-expire"`
}

type ROAJsonSimple struct {
type VRPJsonSimple struct {
ASN uint32 `json:"asn"`
Length uint8 `json:"max-length"`
Prefix string `json:"prefix"`
Expand All @@ -516,8 +516,8 @@ type ROAJsonSimple struct {
type diffExport struct {
MetadataPrimary *diffMetadata `json:"metadata-primary"`
MetadataSecondary *diffMetadata `json:"metadata-secondary"`
OnlyInPrimary []*ROAJsonSimple `json:"only-primary"`
OnlyInSecondary []*ROAJsonSimple `json:"only-secondary"`
OnlyInPrimary []*VRPJsonSimple `json:"only-primary"`
OnlyInSecondary []*VRPJsonSimple `json:"only-secondary"`
}

func (c *Comparator) ServeDiff(wr http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -553,11 +553,11 @@ func (c *Comparator) Compare() {
case id := <-c.comp:
log.Infof("Worker %d finished: comparison", id)

roas1, md1 := c.PrimaryClient.GetData()
roas2, md2 := c.SecondaryClient.GetData()
vrps1, md1 := c.PrimaryClient.GetData()
vrps2, md2 := c.SecondaryClient.GetData()

onlyIn1 := Diff(roas1, roas2)
onlyIn2 := Diff(roas2, roas1)
onlyIn1 := Diff(vrps1, vrps2)
onlyIn2 := Diff(vrps2, vrps1)

c.diffLock.Lock()
c.onlyIn1 = onlyIn1
Expand All @@ -566,28 +566,28 @@ func (c *Comparator) Compare() {
c.md1 = md1
c.md2 = md2

ROACount.With(
VRPCount.With(
prometheus.Labels{
"server": "primary",
"url": md1.URL,
"type": "total",
}).Set(float64(len(roas1)))
}).Set(float64(len(vrps1)))

ROACount.With(
VRPCount.With(
prometheus.Labels{
"server": "primary",
"url": md1.URL,
"type": "diff",
}).Set(float64(len(onlyIn1)))

ROACount.With(
VRPCount.With(
prometheus.Labels{
"server": "secondary",
"url": md1.URL,
"type": "total",
}).Set(float64(len(roas2)))
}).Set(float64(len(vrps2)))

ROACount.With(
VRPCount.With(
prometheus.Labels{
"server": "secondary",
"url": md1.URL,
Expand Down
Loading

0 comments on commit f384479

Please sign in to comment.