bgpwtf/cccampix: add IRR daemon
We add a small IRR service for getting a parsed RPSL from IRRs. For now,
we only support RIPE and ARIN, and only the following attributes:
- remarks
- import
- export
Since RPSL/RFC2622 is fucking insane, there is no guarantee that the
parser, especially the import/export parser, is correct. But it should
be good enough for our use. We even throw in some tests for good
measure.
$ grpcurl -format text -plaintext -d 'as: "26625"' 127.0.0.1:4200 ix.IRR.Query
source: SOURCE_ARIN
attributes: <
import: <
expressions: <
peering: "AS6083"
actions: "pref=10"
>
filter: "ANY"
>
>
attributes: <
import: <
expressions: <
peering: "AS12491"
actions: "pref=10"
>
filter: "ANY"
>
>
Change-Id: I8b240ffe2cd3553a25ce33dbd3917c0aef64e804
diff --git a/bgpwtf/cccampix/irr/provider/rpsl_test.go b/bgpwtf/cccampix/irr/provider/rpsl_test.go
new file mode 100644
index 0000000..2c0fe57
--- /dev/null
+++ b/bgpwtf/cccampix/irr/provider/rpsl_test.go
@@ -0,0 +1,64 @@
+package provider
+
+import (
+ "testing"
+
+ pb "code.hackerspace.pl/hscloud/bgpwtf/cccampix/proto"
+ "github.com/go-test/deep"
+)
+
+func TestParseImportExport(t *testing.T) {
+ tests := []struct {
+ ut string
+ want *pb.IRRAttribute_ImportExport
+ }{
+ {
+ ut: `
+ from AS10674 209.251.128.177 at 216.155.103.20 action pref = 1;
+ accept ANY AND NOT AS-ACCELERATION-CUST
+ `,
+ want: &pb.IRRAttribute_ImportExport{
+ Expressions: []*pb.IRRAttribute_ImportExport_Expression{
+ {
+ Peering: "AS10674",
+ RouterUs: "216.155.103.20",
+ RouterThem: "209.251.128.177",
+ Actions: []string{"pref = 1"},
+ },
+ },
+ Filter: "ANY AND NOT AS-ACCELERATION-CUST",
+ },
+ },
+ {
+ ut: `
+ to AS201054 94.246.185.174 at 94.246.185.175 announce AS-BGPWTF
+ `,
+ want: &pb.IRRAttribute_ImportExport{
+ Expressions: []*pb.IRRAttribute_ImportExport_Expression{
+ {
+ Peering: "AS201054",
+ RouterUs: "94.246.185.175",
+ RouterThem: "94.246.185.174",
+ Actions: []string{},
+ },
+ },
+ Filter: "AS-BGPWTF",
+ },
+ },
+ {
+ // Invalid - unterminated action.
+ ut: `
+ to AS201054 94.246.185.174 at 94.246.185.175 action foo = bar
+ accept ANY AND NOT AS-ACCELERATION-CUST
+ `,
+ want: nil,
+ },
+ }
+
+ for _, test := range tests {
+ res := parseImportExport(test.ut)
+ if diff := deep.Equal(test.want, res); diff != nil {
+ t.Error(diff)
+ }
+ }
+}