Merge pull request #107 from cjeker/naming_is_hard

Naming is hard
This commit is contained in:
Job Snijders
2023-12-21 16:21:03 +01:00
committed by GitHub
10 changed files with 139 additions and 151 deletions
+7 -7
View File
@@ -69,7 +69,7 @@ var (
)
type Client struct {
Data prefixfile.VRPList
Data prefixfile.RPKIList
InitSerial bool
Serial uint32
@@ -84,7 +84,7 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
ASN: uint32(pdu.ASN),
Length: pdu.MaxLen,
}
c.Data.Data = append(c.Data.Data, rj)
c.Data.ROA = append(c.Data.ROA, rj)
c.Data.Metadata.Counts++
if *LogDataPDU {
@@ -96,7 +96,7 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
ASN: uint32(pdu.ASN),
Length: pdu.MaxLen,
}
c.Data.Data = append(c.Data.Data, rj)
c.Data.ROA = append(c.Data.ROA, rj)
c.Data.Metadata.Counts++
if *LogDataPDU {
@@ -117,9 +117,9 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
case *rtr.PDUASPA:
if c.Data.ASPA == nil {
c.Data.ASPA = make([]prefixfile.ASPAJson, 0)
c.Data.ASPA = make([]prefixfile.VAPJson, 0)
}
aj := prefixfile.ASPAJson{
aj := prefixfile.VAPJson{
CustomerAsid: pdu.CustomerASNumber,
Providers: pdu.ProviderASNumbers,
}
@@ -182,9 +182,9 @@ func main() {
}
client := &Client{
Data: prefixfile.VRPList{
Data: prefixfile.RPKIList{
Metadata: prefixfile.MetaData{},
Data: make([]prefixfile.VRPJson, 0),
ROA: make([]prefixfile.VRPJson, 0),
},
InitSerial: *InitSerial,
Serial: uint32(*Serial),
+4 -4
View File
@@ -199,11 +199,11 @@ func (t *thresholds) Set(value string) error {
return nil
}
func decodeJSON(data []byte) (*prefixfile.VRPList, error) {
func decodeJSON(data []byte) (*prefixfile.RPKIList, error) {
buf := bytes.NewBuffer(data)
dec := json.NewDecoder(buf)
var vrplistjson prefixfile.VRPList
var vrplistjson prefixfile.RPKIList
err := dec.Decode(&vrplistjson)
return &vrplistjson, err
}
@@ -369,8 +369,8 @@ func (c *Client) Start(id int, ch chan int) {
// * contains all the VRPs in newVRPs
// * keeps the firstSeen value for VRPs already in the old map
// * keeps elements around for GracePeriod after they are not in the input.
func BuildNewVrpMap(log *log.Entry, currentVrps VRPMap, pfxFile *prefixfile.VRPList, now time.Time) (VRPMap, int) {
var newVrps = pfxFile.Data
func BuildNewVrpMap(log *log.Entry, currentVrps VRPMap, pfxFile *prefixfile.RPKIList, now time.Time) (VRPMap, int) {
var newVrps = pfxFile.ROA
tCurrentUpdate := now.Unix()
res := make(VRPMap)
+18 -18
View File
@@ -11,9 +11,9 @@ import (
func TestBuildNewVrpMap_expiry(t *testing.T) {
stuff := testDataFile()
emptyFile := &prefixfile.VRPList{
emptyFile := &prefixfile.RPKIList{
Metadata: prefixfile.MetaData{},
Data: []prefixfile.VRPJson{},
ROA: []prefixfile.VRPJson{},
BgpSecKeys: []prefixfile.BgpSecKeyJson{},
}
@@ -36,9 +36,9 @@ func TestBuildNewVrpMap_expiry(t *testing.T) {
res, inGracePeriod = BuildNewVrpMap(log, res, emptyFile, t1)
assertLastSeenMatchesTimeCount(t, res, t1, 0)
assertLastSeenMatchesTimeCount(t, res, now, len(stuff.Data))
if inGracePeriod != len(stuff.Data) {
t.Errorf("All objects should be in grace period. Expected: %d, actual: %d", len(stuff.Data), inGracePeriod)
assertLastSeenMatchesTimeCount(t, res, now, len(stuff.ROA))
if inGracePeriod != len(stuff.ROA) {
t.Errorf("All objects should be in grace period. Expected: %d, actual: %d", len(stuff.ROA), inGracePeriod)
}
// 1s after grace period ends, they are removed
@@ -59,18 +59,18 @@ func TestBuildNewVrpMap_firsSeen_lastSeen(t *testing.T) {
var res, _ = BuildNewVrpMap(log, make(VRPMap), stuff, t0)
// All have firstSeen + lastSeen equal to t0
assertFirstSeenMatchesTimeCount(t, res, t0, len(stuff.Data))
assertLastSeenMatchesTimeCount(t, res, t0, len(stuff.Data))
assertVisibleMatchesTimeCount(t, res, len(stuff.Data))
assertFirstSeenMatchesTimeCount(t, res, t0, len(stuff.ROA))
assertLastSeenMatchesTimeCount(t, res, t0, len(stuff.ROA))
assertVisibleMatchesTimeCount(t, res, len(stuff.ROA))
// Supply same data again later
t1 := t0.Add(time.Minute * 10)
res, _ = BuildNewVrpMap(log, res, stuff, t1)
// FirstSeen is constant, LastSeen gets updated, none removed
assertFirstSeenMatchesTimeCount(t, res, t0, len(stuff.Data))
assertLastSeenMatchesTimeCount(t, res, t1, len(stuff.Data))
assertVisibleMatchesTimeCount(t, res, len(stuff.Data))
assertFirstSeenMatchesTimeCount(t, res, t0, len(stuff.ROA))
assertLastSeenMatchesTimeCount(t, res, t1, len(stuff.ROA))
assertVisibleMatchesTimeCount(t, res, len(stuff.ROA))
// Supply one new VRP, expect one at new time, others at old time
otherStuff := []prefixfile.VRPJson{
@@ -81,17 +81,17 @@ func TestBuildNewVrpMap_firsSeen_lastSeen(t *testing.T) {
TA: "testrir",
},
}
otherStuffFile := prefixfile.VRPList{
otherStuffFile := prefixfile.RPKIList{
Metadata: prefixfile.MetaData{},
Data: otherStuff,
ROA: otherStuff,
BgpSecKeys: []prefixfile.BgpSecKeyJson{},
}
t2 := t1.Add(time.Minute * 10)
res, _ = BuildNewVrpMap(log, res, &otherStuffFile, t2)
// LastSeen gets updated just for the new item
assertFirstSeenMatchesTimeCount(t, res, t0, len(stuff.Data))
assertLastSeenMatchesTimeCount(t, res, t1, len(stuff.Data))
assertFirstSeenMatchesTimeCount(t, res, t0, len(stuff.ROA))
assertLastSeenMatchesTimeCount(t, res, t1, len(stuff.ROA))
assertFirstSeenMatchesTimeCount(t, res, t2, len(otherStuff))
assertLastSeenMatchesTimeCount(t, res, t2, len(otherStuff))
@@ -164,10 +164,10 @@ func testData() []prefixfile.VRPJson {
return stuff
}
func testDataFile() *prefixfile.VRPList {
stuff := prefixfile.VRPList{
func testDataFile() *prefixfile.RPKIList {
stuff := prefixfile.RPKIList{
Metadata: prefixfile.MetaData{},
Data: testData(),
ROA: testData(),
BgpSecKeys: []prefixfile.BgpSecKeyJson{},
}
return &stuff
+25 -25
View File
@@ -173,13 +173,13 @@ func newSHA256(data []byte) []byte {
return hash[:]
}
func decodeJSON(data []byte) (*prefixfile.VRPList, error) {
func decodeJSON(data []byte) (*prefixfile.RPKIList, error) {
buf := bytes.NewBuffer(data)
dec := json.NewDecoder(buf)
var vrplistjson prefixfile.VRPList
err := dec.Decode(&vrplistjson)
return &vrplistjson, err
var rpkilistjson prefixfile.RPKIList
err := dec.Decode(&rpkilistjson)
return &rpkilistjson, err
}
func isValidPrefixLength(prefix netip.Prefix, maxLength uint8) bool {
@@ -200,7 +200,7 @@ func isValidPrefixLength(prefix netip.Prefix, maxLength uint8) bool {
// Will return a deduped slice, as well as total VRPs, IPv4 VRPs, IPv6 VRPs, BGPsec Keys and ASPA records
func processData(vrplistjson []prefixfile.VRPJson,
brklistjson []prefixfile.BgpSecKeyJson,
aspajson []prefixfile.ASPAJson) /*Export*/ ([]rtr.VRP, []rtr.BgpsecKey, []rtr.VAP, int, int, int) {
aspajson []prefixfile.VAPJson) /*Export*/ ([]rtr.VRP, []rtr.BgpsecKey, []rtr.VAP, int, int, int) {
filterDuplicates := make(map[string]struct{})
// It may be tempting to change this to a simple time.Since() but that will
@@ -342,13 +342,13 @@ func (e IdenticalFile) Error() string {
return fmt.Sprintf("File %s is identical to the previous version", e.File)
}
var errVRPJsonFileTooOld = errors.New("VRP JSON file is older than 24 hours")
var errRPKIJsonFileTooOld = errors.New("RPKI JSON file is older than 24 hours")
// Update the state based on the current slurm file and data.
func (s *state) updateFromNewState() error {
sessid := s.server.GetSessionId()
vrpsjson := s.lastdata.Data
vrpsjson := s.lastdata.ROA
if vrpsjson == nil {
return nil
}
@@ -358,7 +358,7 @@ func (s *state) updateFromNewState() error {
}
aspajson := s.lastdata.ASPA
if aspajson == nil {
aspajson = make([]prefixfile.ASPAJson, 0)
aspajson = make([]prefixfile.VAPJson, 0)
}
buildtime, err := time.Parse(time.RFC3339, s.lastdata.Metadata.Buildtime)
@@ -371,8 +371,8 @@ func (s *state) updateFromNewState() error {
}
notafter := buildtime.Add(time.Hour * 24)
if time.Now().UTC().After(notafter) {
log.Warnf("VRP JSON file is older than 24 hours: %v", buildtime)
return errVRPJsonFileTooOld
log.Warnf("RPKI JSON file is older than 24 hours: %v", buildtime)
return errRPKIJsonFileTooOld
}
}
@@ -390,7 +390,7 @@ func (s *state) updateFromNewState() error {
func (s *state) reloadFromCurrentState() error {
sessid := s.server.GetSessionId()
vrpsjson := s.lastdata.Data
vrpsjson := s.lastdata.ROA
if vrpsjson == nil {
return nil
}
@@ -400,7 +400,7 @@ func (s *state) reloadFromCurrentState() error {
}
aspajson := s.lastdata.ASPA
if aspajson == nil {
aspajson = make([]prefixfile.ASPAJson, 0)
aspajson = make([]prefixfile.VAPJson, 0)
}
buildtime, err := time.Parse(time.RFC3339, s.lastdata.Metadata.Buildtime)
@@ -413,8 +413,8 @@ func (s *state) reloadFromCurrentState() error {
}
notafter := buildtime.Add(time.Hour * 24)
if time.Now().UTC().After(notafter) {
log.Warnf("VRP JSON file is older than 24 hours: %v", buildtime)
return errVRPJsonFileTooOld
log.Warnf("RPKI JSON file is older than 24 hours: %v", buildtime)
return errRPKIJsonFileTooOld
}
}
@@ -423,8 +423,8 @@ func (s *state) reloadFromCurrentState() error {
}
vrps, brks, vaps, count, countv4, countv6 := processData(vrpsjson, bgpsecjson, aspajson)
if s.server.CountVRPs() != count {
log.Infof("New update to old state (%v uniques, %v total prefixes). (old %v - new %v)", len(vrps), count, s.server.CountVRPs(), count)
if s.server.CountSDs() != count {
log.Infof("New update to old state (%v uniques, %v total prefixes). (old %v - new %v)", len(vrps), count, s.server.CountSDs(), count)
return s.applyUpdateFromNewState(vrps, brks, vaps, sessid, vrpsjson, bgpsecjson, aspajson, countv4, countv6)
}
return nil
@@ -432,7 +432,7 @@ func (s *state) reloadFromCurrentState() error {
func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey, vaps []rtr.VAP,
sessid uint16,
vrpsjson []prefixfile.VRPJson, brksjson []prefixfile.BgpSecKeyJson, aspajson []prefixfile.ASPAJson,
vrpsjson []prefixfile.VRPJson, brksjson []prefixfile.BgpSecKeyJson, aspajson []prefixfile.VAPJson,
countv4 int, countv6 int) error {
SDs := make([]rtr.SendableData, 0, len(vrps)+len(brks)+len(vaps))
@@ -455,12 +455,12 @@ func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey, va
}
s.lockJson.Lock()
s.exported = prefixfile.VRPList{
s.exported = prefixfile.RPKIList{
Metadata: prefixfile.MetaData{
Counts: len(vrpsjson),
Buildtime: s.lastdata.Metadata.Buildtime,
},
Data: vrpsjson,
ROA: vrpsjson,
BgpSecKeys: brksjson,
ASPA: aspajson,
}
@@ -508,14 +508,14 @@ func (s *state) updateFile(file string) (bool, error) {
log.Infof("new cache file: Updating sha256 hash %x -> %x", s.lasthash, hsum)
vrplistjson, err := decodeJSON(data)
rpkilistjson, err := decodeJSON(data)
if err != nil {
return false, err
}
s.lasthash = hsum
s.lastchange = time.Now().UTC()
s.lastdata = vrplistjson
s.lastdata = rpkilistjson
return true, nil
}
@@ -617,7 +617,7 @@ func (s *state) routineUpdate(file string, interval int, slurmFile string) {
if cacheUpdated || slurmNotPresentOrUpdated {
err := s.updateFromNewState()
if err != nil {
if err == errVRPJsonFileTooOld {
if err == errRPKIJsonFileTooOld {
// If the exiting build time is over 24 hours, It's time to drop everything out.
// to avoid routing on stale data
buildTime := s.exported.Metadata.GetBuildTime()
@@ -645,7 +645,7 @@ func (s *state) exporter(wr http.ResponseWriter, r *http.Request) {
}
type state struct {
lastdata *prefixfile.VRPList
lastdata *prefixfile.RPKIList
lasthash []byte
lastchange time.Time
lastts time.Time
@@ -657,7 +657,7 @@ type state struct {
metricsEvent *metricsEvent
exported prefixfile.VRPList
exported prefixfile.RPKIList
lockJson *sync.RWMutex
slurm *prefixfile.SlurmConfig
@@ -754,7 +754,7 @@ func run() error {
s := state{
server: server,
lastdata: &prefixfile.VRPList{},
lastdata: &prefixfile.RPKIList{},
metricsEvent: me,
sendNotifs: *SendNotifs,
checktime: *TimeCheck,
+2 -2
View File
@@ -156,12 +156,12 @@ func TestJson(t *testing.T) {
Ex1 := int64(1627568318)
Ex2 := int64(1627575699)
want := (&prefixfile.VRPList{
want := (&prefixfile.RPKIList{
Metadata: prefixfile.MetaData{
Counts: 2,
Buildtime: "2021-07-27T18:56:02Z",
},
Data: []prefixfile.VRPJson{
ROA: []prefixfile.VRPJson{
{Prefix: "1.0.0.0/24",
Length: 24,
ASN: float64(13335),
+3 -3
View File
@@ -16,7 +16,7 @@ var (
)
type TestClient struct {
Data prefixfile.VRPList
Data prefixfile.RPKIList
InitSerial bool
Serial uint32
@@ -34,9 +34,9 @@ func getBasicClientConguration(version int) ClientConfiguration {
func getClient() *TestClient {
return &TestClient{
Data: prefixfile.VRPList{
Data: prefixfile.RPKIList{
Metadata: prefixfile.MetaData{},
Data: make([]prefixfile.VRPJson, 0),
ROA: make([]prefixfile.VRPJson, 0),
},
InitSerial: InitSerial,
Serial: Serial,
+43 -54
View File
@@ -74,16 +74,16 @@ func (e *DefaultRTREventHandler) RequestCache(c *Client) {
e.Log.Debugf("%v < No data", c)
}
} else {
vrps, exists := e.sdManager.GetCurrentSDs()
data, exists := e.sdManager.GetCurrentSDs()
if !exists {
c.SendInternalError()
if e.Log != nil {
e.Log.Debugf("%v < Internal error requesting cache (does not exists)", c)
}
} else {
c.SendSDs(sessionId, serial, vrps)
c.SendSDs(sessionId, serial, data)
if e.Log != nil {
e.Log.Debugf("%v < Sent VRPs (current serial %d, session: %d)", c, serial, sessionId)
e.Log.Debugf("%v < Sent cache (current serial %d, session: %d)", c, serial, sessionId)
}
}
}
@@ -109,16 +109,16 @@ func (e *DefaultRTREventHandler) RequestNewVersion(c *Client, sessionId uint16,
e.Log.Debugf("%v < No data", c)
}
} else {
vrps, exists := e.sdManager.GetSDsSerialDiff(serialNumber)
data, exists := e.sdManager.GetSDsSerialDiff(serialNumber)
if !exists {
c.SendCacheReset()
if e.Log != nil {
e.Log.Debugf("%v < Sent cache reset", c)
}
} else {
c.SendSDs(sessionId, serial, vrps)
c.SendSDs(sessionId, serial, data)
if e.Log != nil {
e.Log.Debugf("%v < Sent VRPs (current serial %d, session from client: %d)", c, serial, sessionId)
e.Log.Debugf("%v < Sent cache (current serial %d, session from client: %d)", c, serial, sessionId)
}
}
}
@@ -145,7 +145,6 @@ type Server struct {
sdCurrent []SendableData
sdCurrentSerial uint32
keepDiff int
manualserial bool
pduRefreshInterval uint32
pduRetryInterval uint32
@@ -229,22 +228,22 @@ func ComputeDiff(newSDs, prevSDs []SendableData, populateUnchanged bool) (added,
newSDsMap := ConvertSDListToMap(newSDs)
prevSDsMap := ConvertSDListToMap(prevSDs)
for _, vrp := range newSDs {
_, exists := prevSDsMap[vrp.HashKey()]
for _, item := range newSDs {
_, exists := prevSDsMap[item.HashKey()]
if !exists {
rcopy := vrp.Copy()
rcopy := item.Copy()
rcopy.SetFlag(FLAG_ADDED)
added = append(added, rcopy)
}
}
for _, vrp := range prevSDs {
_, exists := newSDsMap[vrp.HashKey()]
for _, item := range prevSDs {
_, exists := newSDsMap[item.HashKey()]
if !exists {
rcopy := vrp.Copy()
rcopy := item.Copy()
rcopy.SetFlag(FLAG_REMOVED)
removed = append(removed, rcopy)
} else if populateUnchanged {
rcopy := vrp.Copy()
rcopy := item.Copy()
unchanged = append(unchanged, rcopy)
}
}
@@ -257,25 +256,25 @@ func ApplyDiff(diff, prevSDs []SendableData) []SendableData {
diffMap := ConvertSDListToMap(diff)
prevSDsMap := ConvertSDListToMap(prevSDs)
for _, vrp := range prevSDs {
_, exists := diffMap[vrp.HashKey()]
for _, item := range prevSDs {
_, exists := diffMap[item.HashKey()]
if !exists {
rcopy := vrp.Copy()
rcopy := item.Copy()
newSDs = append(newSDs, rcopy)
}
}
for _, vrp := range diff {
if vrp.GetFlag() == FLAG_ADDED {
rcopy := vrp.Copy()
for _, item := range diff {
if item.GetFlag() == FLAG_ADDED {
rcopy := item.Copy()
newSDs = append(newSDs, rcopy)
} else if vrp.GetFlag() == FLAG_REMOVED {
cvrp, exists := prevSDsMap[vrp.HashKey()]
} else if item.GetFlag() == FLAG_REMOVED {
citem, exists := prevSDsMap[item.HashKey()]
if !exists {
rcopy := vrp.Copy()
rcopy := item.Copy()
newSDs = append(newSDs, rcopy)
} else {
if cvrp == FLAG_REMOVED {
rcopy := vrp.Copy()
if citem == FLAG_REMOVED {
rcopy := item.Copy()
newSDs = append(newSDs, rcopy)
}
}
@@ -285,26 +284,22 @@ func ApplyDiff(diff, prevSDs []SendableData) []SendableData {
return newSDs
}
func (s *Server) SetManualSerial(v bool) {
s.manualserial = v
}
func (s *Server) GetSessionId() uint16 {
return s.sessId
}
func (s *Server) GetCurrentSDs() ([]SendableData, bool) {
s.sdlock.RLock()
vrp := s.sdCurrent
sd := s.sdCurrent
s.sdlock.RUnlock()
return vrp, true
return sd, true
}
func (s *Server) GetSDsSerialDiff(serial uint32) ([]SendableData, bool) {
s.sdlock.RLock()
vrp, ok := s.getSDsSerialDiff(serial)
sd, ok := s.getSDsSerialDiff(serial)
s.sdlock.RUnlock()
return vrp, ok
return sd, ok
}
func (s *Server) getSDsSerialDiff(serial uint32) ([]SendableData, bool) {
@@ -312,12 +307,12 @@ func (s *Server) getSDsSerialDiff(serial uint32) ([]SendableData, bool) {
return []SendableData{}, true
}
vrp := make([]SendableData, 0)
sd := make([]SendableData, 0)
index, ok := s.sdMapSerial[serial]
if ok {
vrp = s.sdListDiff[index]
sd = s.sdListDiff[index]
}
return vrp, ok
return sd, ok
}
func (s *Server) GetCurrentSerial(sessId uint16) (uint32, bool) {
@@ -340,7 +335,7 @@ func (s *Server) GenerateSerial() uint32 {
func (s *Server) generateSerial() uint32 {
newserial := s.sdCurrentSerial
if !s.manualserial && len(s.sdListSerial) > 0 {
if len(s.sdListSerial) > 0 {
newserial = s.sdListSerial[len(s.sdListSerial)-1] + 1
}
return newserial
@@ -351,31 +346,25 @@ func (s *Server) setSerial(serial uint32) {
}
// This function sets the serial. Function must
// be called before the VRPs data is added.
// be called before the cache data is added.
func (s *Server) SetSerial(serial uint32) {
s.sdlock.RLock()
defer s.sdlock.RUnlock()
//s.vrpListSerial = make([]uint32, 0)
//s.sdListSerial = make([]uint32, 0)
s.setSerial(serial)
}
func (s *Server) CountVRPs() int {
func (s *Server) CountSDs() int {
s.sdlock.RLock()
defer s.sdlock.RUnlock()
return len(s.sdCurrent)
}
func (s *Server) AddData(vrps []SendableData) {
func (s *Server) AddData(new []SendableData) {
s.sdlock.RLock()
// a slight hack for now, until we have BGPsec/ASPA support
vrpsAsSD := make([]SendableData, 0, len(vrps))
for _, v := range vrps {
vrpsAsSD = append(vrpsAsSD, v.Copy())
}
added, removed, _ := ComputeDiff(vrpsAsSD, s.sdCurrent, false)
added, removed, _ := ComputeDiff(new, s.sdCurrent, false)
if s.log != nil && s.logverbose {
s.log.Debugf("Computed diff: added (%v), removed (%v)", added, removed)
} else if s.log != nil {
@@ -401,10 +390,10 @@ func (s *Server) addSerial(serial uint32) []uint32 {
func (s *Server) AddSDsDiff(diff []SendableData) {
s.sdlock.RLock()
nextDiff := make([][]SendableData, len(s.sdListDiff))
for i, prevVrps := range s.sdListDiff {
nextDiff[i] = ApplyDiff(diff, prevVrps)
for i, prevSDs := range s.sdListDiff {
nextDiff[i] = ApplyDiff(diff, prevSDs)
}
newVrpCurrent := ApplyDiff(diff, s.sdCurrent)
newSDCurrent := ApplyDiff(diff, s.sdCurrent)
curserial, _ := s.getCurrentSerial()
s.sdlock.RUnlock()
@@ -432,7 +421,7 @@ func (s *Server) AddSDsDiff(diff []SendableData) {
delete(s.sdMapSerial, removeSerial)
}
s.sdListDiff = nextDiff
s.sdCurrent = newVrpCurrent
s.sdCurrent = newSDCurrent
s.setSerial(newserial)
}
@@ -1027,8 +1016,8 @@ func (c *Client) SendSDs(sessionId uint16, serialNumber uint32, data []SendableD
SessionId: sessionId,
}
c.SendPDU(pduBegin)
for _, data := range data {
c.SendData(data.Copy())
for _, item := range data {
c.SendData(item.Copy())
}
pduEnd := &PDUEndOfData{
SessionId: sessionId,
+24 -25
View File
@@ -8,6 +8,21 @@ import (
"time"
)
type RPKIList struct {
Metadata MetaData `json:"metadata,omitempty"`
ROA []VRPJson `json:"roas"` // for historical reasons this is called 'roas', but should've been called vrps
BgpSecKeys []BgpSecKeyJson `json:"bgpsec_keys,omitempty"`
ASPA []VAPJson `json:"aspas,omitempty"`
}
type MetaData struct {
Counts int `json:"vrps"`
CountASPAs int `json:"aspas"`
CountBgpSecKeys int `json:"bgpsec_pubkeys"`
Buildtime string `json:"buildtime,omitempty"`
GeneratedUnix *int64 `json:"generated,omitempty"`
}
type VRPJson struct {
Prefix string `json:"prefix"`
Length uint8 `json:"maxLength"`
@@ -16,29 +31,6 @@ type VRPJson struct {
Expires *int64 `json:"expires,omitempty"`
}
type MetaData struct {
Counts int `json:"vrps"`
CountASPAs int `json:"aspas"`
CountBgpSecKeys int `json:"aspas"`
Buildtime string `json:"buildtime,omitempty"`
GeneratedUnix *int64 `json:"generated,omitempty"`
}
func (md MetaData) GetBuildTime() time.Time {
bt, err := time.Parse(time.RFC3339, md.Buildtime)
if err != nil {
return time.Time{}
}
return bt
}
type VRPList struct {
Metadata MetaData `json:"metadata,omitempty"`
Data []VRPJson `json:"roas"` // for historical reasons this is called 'roas', but should've been called vrps
BgpSecKeys []BgpSecKeyJson `json:"bgpsec_keys,omitempty"`
ASPA []ASPAJson `json:"aspas,omitempty"`
}
type BgpSecKeyJson struct {
Asn uint32 `json:"asn"`
Expires *int64 `json:"expires,omitempty"`
@@ -52,13 +44,20 @@ type BgpSecKeyJson struct {
Ski string `json:"ski"`
}
// ASPA
type ASPAJson struct {
type VAPJson struct {
CustomerAsid uint32 `json:"customer_asid"`
Expires *int64 `json:"expires,omitempty"`
Providers []uint32 `json:"providers"`
}
func (md MetaData) GetBuildTime() time.Time {
bt, err := time.Parse(time.RFC3339, md.Buildtime)
if err != nil {
return time.Time{}
}
return bt
}
func (vrp *VRPJson) GetASN2() (uint32, error) {
switch asnc := vrp.ASN.(type) {
case string:
+9 -9
View File
@@ -207,9 +207,9 @@ func (s *SlurmValidationOutputFilters) FilterOnBRKs(brks []BgpSecKeyJson) (added
return added, removed
}
func (s *SlurmValidationOutputFilters) FilterOnVAPs(vaps []ASPAJson, ipv6 bool) (added, removed []ASPAJson) {
added = make([]ASPAJson, 0)
removed = make([]ASPAJson, 0)
func (s *SlurmValidationOutputFilters) FilterOnVAPs(vaps []VAPJson, ipv6 bool) (added, removed []VAPJson) {
added = make([]VAPJson, 0)
removed = make([]VAPJson, 0)
if s.AspaFilters == nil || len(s.AspaFilters) == 0 {
return vaps, removed
}
@@ -259,14 +259,14 @@ func (s *SlurmLocallyAddedAssertions) AssertVRPs() []VRPJson {
return vrps
}
func (s *SlurmLocallyAddedAssertions) AssertVAPs() []ASPAJson {
vaps := make([]ASPAJson, 0)
func (s *SlurmLocallyAddedAssertions) AssertVAPs() []VAPJson {
vaps := make([]VAPJson, 0)
if s.AspaAssertions == nil || len(s.AspaAssertions) == 0 {
return vaps
}
for _, assertion := range s.AspaAssertions {
vap := ASPAJson{
vap := VAPJson{
CustomerAsid: assertion.CustomerASNid,
Providers: assertion.ProviderSet,
}
@@ -293,15 +293,15 @@ func (s *SlurmLocallyAddedAssertions) AssertBRKs() []BgpSecKeyJson {
return brks
}
func (s *SlurmConfig) GetAssertions() (vrps []VRPJson, vaps []ASPAJson, BRKs []BgpSecKeyJson) {
func (s *SlurmConfig) GetAssertions() (vrps []VRPJson, vaps []VAPJson, BRKs []BgpSecKeyJson) {
vrps = s.LocallyAddedAssertions.AssertVRPs()
vaps = s.LocallyAddedAssertions.AssertVAPs()
BRKs = s.LocallyAddedAssertions.AssertBRKs()
return
}
func (s *SlurmConfig) FilterAssert(vrps []VRPJson, vaps []ASPAJson, BRKs []BgpSecKeyJson, log Logger) (
ovrps []VRPJson, ovaps []ASPAJson, oBRKs []BgpSecKeyJson) {
func (s *SlurmConfig) FilterAssert(vrps []VRPJson, vaps []VAPJson, BRKs []BgpSecKeyJson, log Logger) (
ovrps []VRPJson, ovaps []VAPJson, oBRKs []BgpSecKeyJson) {
//
filteredVRPs, removedVRPs := s.ValidationOutputFilters.FilterOnVRPs(vrps)
filteredVAPs, removedVAPs := s.ValidationOutputFilters.FilterOnVAPs(vaps, false)
+4 -4
View File
@@ -189,7 +189,7 @@ func TestFilterOnBSKs(t *testing.T) {
assert.Equal(t, uint32(65005), removed[2].Asn)
}
func TestFilterOnVAPs(t *testing.T) {
vrps := []ASPAJson{
vrps := []VAPJson{
{
CustomerAsid: 65001,
Providers: []uint32{65002, 65003},
@@ -242,7 +242,7 @@ func TestSlurmEndToEnd(t *testing.T) {
}
finalVRP, finalASPA, finalBgpsec :=
config.FilterAssert(vrplist.Data, vrplist.ASPA, vrplist.BgpSecKeys, nil)
config.FilterAssert(vrplist.ROA, vrplist.ASPA, vrplist.BgpSecKeys, nil)
foundAssertVRP := false
for _, vrps := range finalVRP {
@@ -285,11 +285,11 @@ func TestSlurmEndToEnd(t *testing.T) {
}
}
func decodeJSON(data []byte) (*VRPList, error) {
func decodeJSON(data []byte) (*RPKIList, error) {
buf := bytes.NewBuffer(data)
dec := json.NewDecoder(buf)
var vrplistjson VRPList
var vrplistjson RPKIList
err := dec.Decode(&vrplistjson)
return &vrplistjson, err
}