Skip to content
Browse files

Store all the parsed route data in the trie

  • Loading branch information...
1 parent f2fb56f commit 5c487ea3999d25d014ade9d807f40abc4eea52c6 @abh committed Jan 10, 2013
Showing with 13 additions and 9 deletions.
  1. +3 −2 bgpreader.go
  2. +6 −3 http.go
  3. +4 −4 trie.go
View
5 bgpreader.go
@@ -109,15 +109,15 @@ func processLine(line string) {
neighbor.AsnPrefix[route.PrimaryASN][route.Prefix.String()] = 0
neighbor.PrefixAsn[route.Prefix.String()] = route.PrimaryASN
- addRoute(neighbor.trie, route.Prefix, uint32(route.PrimaryASN))
+ addRoute(neighbor.trie, route.Prefix, route)
}
case "withdrawn":
neighbor.Updates++
route := parseRoute(f[3])
- removeRoute(neighbor.trie, route.Prefix, uint32(route.PrimaryASN))
+ removeRoute(neighbor.trie, route.Prefix)
if asn, exists := neighbor.PrefixAsn[route.Prefix.String()]; exists {
// fmt.Println("Removing ASN from prefix", asn, route.Prefix)
@@ -212,6 +212,7 @@ func parseRoute(input string) *Route {
if len(aspath) > 0 {
route.PrimaryASN = ASN(aspath[len(aspath)-1])
+ route.ASPath = aspath
}
return route
View
9 http.go
@@ -62,6 +62,7 @@ func ApiHandler(w http.ResponseWriter, r *http.Request) {
type ipasnResult struct {
ASN ASN
+ ASPath ASPath `json:",omitempty"`
Name string `json:",omitempty"`
Prefix string `json:",omitempty"`
}
@@ -86,8 +87,10 @@ func ApiHandler(w http.ResponseWriter, r *http.Request) {
node := data.FindNode(&ip)
if node.Bits() > 0 {
result[neighbor] = new(ipasnResult)
+ route := node.Value.(*Route)
r := result[neighbor]
- r.ASN = ASN(node.Value)
+ r.ASN = ASN(route.PrimaryASN)
+ r.ASPath = route.ASPath
r.Name = ""
r.Prefix = nodeToIPNet(node).String()
}
@@ -100,7 +103,7 @@ func ApiHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Could not generate JSON")
}
- fmt.Fprint(w, string(json))
+ fmt.Fprint(w, string(json), "\n")
default:
w.WriteHeader(404)
@@ -259,7 +262,7 @@ const index_tpl = `<!DOCTYPE html>
var request = $.ajax({
url: "/api/ipasn",
- type: "post",
+ type: "get",
data: serializedData
});
View
8 trie.go
@@ -7,12 +7,12 @@ import (
"reflect"
)
-func addRoute(r *bitradix.Radix32, ipnet *net.IPNet, asn uint32) {
+func addRoute(r *bitradix.Radix32, ipnet *net.IPNet, route *Route) {
net, mask := ipNetToUint(ipnet)
- r.Insert(net, mask, asn)
+ r.Insert(net, mask, route)
}
-func removeRoute(r *bitradix.Radix32, ipnet *net.IPNet, asn uint32) {
+func removeRoute(r *bitradix.Radix32, ipnet *net.IPNet) {
net, mask := ipNetToUint(ipnet)
r.Remove(net, mask)
}
@@ -50,5 +50,5 @@ func (n *Neighbor) FindNode(ip *net.IP) *bitradix.Radix32 {
func (n *Neighbor) FindAsn(ip *net.IP) ASN {
node := n.FindNode(ip)
- return ASN(node.Value)
+ return node.Value.(Route).PrimaryASN
}

0 comments on commit 5c487ea

Please sign in to comment.
Something went wrong with that request. Please try again.