Add GoBGP data source
This commit is contained in:
parent
b9956c0246
commit
87642cc4d9
|
@ -4,3 +4,4 @@
|
|||
.*.swo
|
||||
db.sqlite3
|
||||
dnmapper/settings.py
|
||||
__pycache__
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
import grpc
|
||||
|
||||
from backend.gobgp_api import gobgp_pb2_grpc, attribute_pb2
|
||||
from backend.gobgp_api.gobgp_pb2 import TableType, Family, ListPeerRequest, ListPathRequest
|
||||
|
||||
|
||||
def get_bgp_data(gobgp_host):
|
||||
_timeout = 10
|
||||
|
||||
channel = grpc.insecure_channel('{}:50051'.format(gobgp_host))
|
||||
stub = gobgp_pb2_grpc.GobgpApiStub(channel)
|
||||
data = []
|
||||
|
||||
peers = stub.ListPeer(ListPeerRequest(), _timeout)
|
||||
for peer in peers:
|
||||
entry = {
|
||||
"local_id": peer.peer.state.router_id,
|
||||
"local_as": peer.peer.conf.peer_as,
|
||||
"peers": [], # we don't export any peers
|
||||
"routes": [],
|
||||
}
|
||||
neigh = peer.peer.conf.neighbor_address
|
||||
|
||||
for af in [Family.Afi.AFI_IP, Family.Afi.AFI_IP6]:
|
||||
req = ListPathRequest(
|
||||
name=neigh,
|
||||
table_type=TableType.ADJ_IN,
|
||||
family=Family(afi=af, safi=Family.Safi.SAFI_UNICAST),
|
||||
sort_type=ListPathRequest.SortType.PREFIX)
|
||||
rib = stub.ListPath(req)
|
||||
for dest in rib:
|
||||
prefix = dest.destination.prefix
|
||||
for path in dest.destination.paths:
|
||||
as_path = []
|
||||
next_hop = "<unknown>" # currently here to prevent error from NOT NULL constraint
|
||||
|
||||
# parse attrs
|
||||
for pattr in path.pattrs:
|
||||
if pattr.type_url == "type.googleapis.com/gobgpapi.NextHopAttribute":
|
||||
nh = attribute_pb2.NextHopAttribute()
|
||||
nh.ParseFromString(pattr.value)
|
||||
next_hop = nh.next_hop
|
||||
elif pattr.type_url == "type.googleapis.com/gobgpapi.AsPathAttribute":
|
||||
asp = attribute_pb2.AsPathAttribute()
|
||||
asp.ParseFromString(pattr.value)
|
||||
for seg in asp.segments:
|
||||
if seg.type == 2:
|
||||
as_path = seg.numbers
|
||||
elif pattr.type_url == "type.googleapis.com/gobgpapi.MpReachNLRIAttribute":
|
||||
mpreach = attribute_pb2.MpReachNLRIAttribute()
|
||||
mpreach.ParseFromString(pattr.value)
|
||||
next_hop = mpreach.next_hops[0]
|
||||
|
||||
if not as_path:
|
||||
continue
|
||||
|
||||
route = {
|
||||
"prefix": prefix,
|
||||
"path": as_path,
|
||||
"nexthop": next_hop,
|
||||
}
|
||||
entry["routes"].append(route)
|
||||
|
||||
data.append(entry)
|
||||
return data
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,3 @@
|
|||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
||||
import grpc
|
||||
|
|
@ -0,0 +1,692 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: capability.proto
|
||||
|
||||
from google.protobuf.internal import enum_type_wrapper
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
import gobgp_pb2 as gobgp__pb2
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='capability.proto',
|
||||
package='gobgpapi',
|
||||
syntax='proto3',
|
||||
serialized_options=None,
|
||||
serialized_pb=b'\n\x10\x63\x61pability.proto\x12\x08gobgpapi\x1a\x0bgobgp.proto\";\n\x17MultiProtocolCapability\x12 \n\x06\x66\x61mily\x18\x01 \x01(\x0b\x32\x10.gobgpapi.Family\"\x18\n\x16RouteRefreshCapability\"\x1d\n\x1b\x43\x61rryingLabelInfoCapability\"q\n\x1e\x45xtendedNexthopCapabilityTuple\x12%\n\x0bnlri_family\x18\x01 \x01(\x0b\x32\x10.gobgpapi.Family\x12(\n\x0enexthop_family\x18\x02 \x01(\x0b\x32\x10.gobgpapi.Family\"U\n\x19\x45xtendedNexthopCapability\x12\x38\n\x06tuples\x18\x01 \x03(\x0b\x32(.gobgpapi.ExtendedNexthopCapabilityTuple\"Q\n\x1eGracefulRestartCapabilityTuple\x12 \n\x06\x66\x61mily\x18\x01 \x01(\x0b\x32\x10.gobgpapi.Family\x12\r\n\x05\x66lags\x18\x02 \x01(\r\"r\n\x19GracefulRestartCapability\x12\r\n\x05\x66lags\x18\x01 \x01(\r\x12\x0c\n\x04time\x18\x02 \x01(\r\x12\x38\n\x06tuples\x18\x03 \x03(\x0b\x32(.gobgpapi.GracefulRestartCapabilityTuple\")\n\x1b\x46ourOctetASNumberCapability\x12\n\n\x02\x61s\x18\x01 \x01(\r\"_\n\x16\x41\x64\x64PathCapabilityTuple\x12 \n\x06\x66\x61mily\x18\x01 \x01(\x0b\x32\x10.gobgpapi.Family\x12#\n\x04mode\x18\x02 \x01(\x0e\x32\x15.gobgpapi.AddPathMode\"E\n\x11\x41\x64\x64PathCapability\x12\x30\n\x06tuples\x18\x01 \x03(\x0b\x32 .gobgpapi.AddPathCapabilityTuple\" \n\x1e\x45nhancedRouteRefreshCapability\"h\n\'LongLivedGracefulRestartCapabilityTuple\x12 \n\x06\x66\x61mily\x18\x01 \x01(\x0b\x32\x10.gobgpapi.Family\x12\r\n\x05\x66lags\x18\x02 \x01(\r\x12\x0c\n\x04time\x18\x03 \x01(\r\"g\n\"LongLivedGracefulRestartCapability\x12\x41\n\x06tuples\x18\x01 \x03(\x0b\x32\x31.gobgpapi.LongLivedGracefulRestartCapabilityTuple\"\x1d\n\x1bRouteRefreshCiscoCapability\"0\n\x11UnknownCapability\x12\x0c\n\x04\x63ode\x18\x01 \x01(\r\x12\r\n\x05value\x18\x02 \x01(\x0c*L\n\x0b\x41\x64\x64PathMode\x12\r\n\tMODE_NONE\x10\x00\x12\x10\n\x0cMODE_RECEIVE\x10\x01\x12\r\n\tMODE_SEND\x10\x02\x12\r\n\tMODE_BOTH\x10\x03\x62\x06proto3'
|
||||
,
|
||||
dependencies=[gobgp__pb2.DESCRIPTOR,])
|
||||
|
||||
_ADDPATHMODE = _descriptor.EnumDescriptor(
|
||||
name='AddPathMode',
|
||||
full_name='gobgpapi.AddPathMode',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
values=[
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='MODE_NONE', index=0, number=0,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='MODE_RECEIVE', index=1, number=1,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='MODE_SEND', index=2, number=2,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='MODE_BOTH', index=3, number=3,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
],
|
||||
containing_type=None,
|
||||
serialized_options=None,
|
||||
serialized_start=1099,
|
||||
serialized_end=1175,
|
||||
)
|
||||
_sym_db.RegisterEnumDescriptor(_ADDPATHMODE)
|
||||
|
||||
AddPathMode = enum_type_wrapper.EnumTypeWrapper(_ADDPATHMODE)
|
||||
MODE_NONE = 0
|
||||
MODE_RECEIVE = 1
|
||||
MODE_SEND = 2
|
||||
MODE_BOTH = 3
|
||||
|
||||
|
||||
|
||||
_MULTIPROTOCOLCAPABILITY = _descriptor.Descriptor(
|
||||
name='MultiProtocolCapability',
|
||||
full_name='gobgpapi.MultiProtocolCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='family', full_name='gobgpapi.MultiProtocolCapability.family', index=0,
|
||||
number=1, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=43,
|
||||
serialized_end=102,
|
||||
)
|
||||
|
||||
|
||||
_ROUTEREFRESHCAPABILITY = _descriptor.Descriptor(
|
||||
name='RouteRefreshCapability',
|
||||
full_name='gobgpapi.RouteRefreshCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=104,
|
||||
serialized_end=128,
|
||||
)
|
||||
|
||||
|
||||
_CARRYINGLABELINFOCAPABILITY = _descriptor.Descriptor(
|
||||
name='CarryingLabelInfoCapability',
|
||||
full_name='gobgpapi.CarryingLabelInfoCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=130,
|
||||
serialized_end=159,
|
||||
)
|
||||
|
||||
|
||||
_EXTENDEDNEXTHOPCAPABILITYTUPLE = _descriptor.Descriptor(
|
||||
name='ExtendedNexthopCapabilityTuple',
|
||||
full_name='gobgpapi.ExtendedNexthopCapabilityTuple',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='nlri_family', full_name='gobgpapi.ExtendedNexthopCapabilityTuple.nlri_family', index=0,
|
||||
number=1, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='nexthop_family', full_name='gobgpapi.ExtendedNexthopCapabilityTuple.nexthop_family', index=1,
|
||||
number=2, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=161,
|
||||
serialized_end=274,
|
||||
)
|
||||
|
||||
|
||||
_EXTENDEDNEXTHOPCAPABILITY = _descriptor.Descriptor(
|
||||
name='ExtendedNexthopCapability',
|
||||
full_name='gobgpapi.ExtendedNexthopCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='tuples', full_name='gobgpapi.ExtendedNexthopCapability.tuples', index=0,
|
||||
number=1, type=11, cpp_type=10, label=3,
|
||||
has_default_value=False, default_value=[],
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=276,
|
||||
serialized_end=361,
|
||||
)
|
||||
|
||||
|
||||
_GRACEFULRESTARTCAPABILITYTUPLE = _descriptor.Descriptor(
|
||||
name='GracefulRestartCapabilityTuple',
|
||||
full_name='gobgpapi.GracefulRestartCapabilityTuple',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='family', full_name='gobgpapi.GracefulRestartCapabilityTuple.family', index=0,
|
||||
number=1, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='flags', full_name='gobgpapi.GracefulRestartCapabilityTuple.flags', index=1,
|
||||
number=2, type=13, cpp_type=3, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=363,
|
||||
serialized_end=444,
|
||||
)
|
||||
|
||||
|
||||
_GRACEFULRESTARTCAPABILITY = _descriptor.Descriptor(
|
||||
name='GracefulRestartCapability',
|
||||
full_name='gobgpapi.GracefulRestartCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='flags', full_name='gobgpapi.GracefulRestartCapability.flags', index=0,
|
||||
number=1, type=13, cpp_type=3, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='time', full_name='gobgpapi.GracefulRestartCapability.time', index=1,
|
||||
number=2, type=13, cpp_type=3, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='tuples', full_name='gobgpapi.GracefulRestartCapability.tuples', index=2,
|
||||
number=3, type=11, cpp_type=10, label=3,
|
||||
has_default_value=False, default_value=[],
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=446,
|
||||
serialized_end=560,
|
||||
)
|
||||
|
||||
|
||||
_FOUROCTETASNUMBERCAPABILITY = _descriptor.Descriptor(
|
||||
name='FourOctetASNumberCapability',
|
||||
full_name='gobgpapi.FourOctetASNumberCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='as', full_name='gobgpapi.FourOctetASNumberCapability.as', index=0,
|
||||
number=1, type=13, cpp_type=3, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=562,
|
||||
serialized_end=603,
|
||||
)
|
||||
|
||||
|
||||
_ADDPATHCAPABILITYTUPLE = _descriptor.Descriptor(
|
||||
name='AddPathCapabilityTuple',
|
||||
full_name='gobgpapi.AddPathCapabilityTuple',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='family', full_name='gobgpapi.AddPathCapabilityTuple.family', index=0,
|
||||
number=1, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='mode', full_name='gobgpapi.AddPathCapabilityTuple.mode', index=1,
|
||||
number=2, type=14, cpp_type=8, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=605,
|
||||
serialized_end=700,
|
||||
)
|
||||
|
||||
|
||||
_ADDPATHCAPABILITY = _descriptor.Descriptor(
|
||||
name='AddPathCapability',
|
||||
full_name='gobgpapi.AddPathCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='tuples', full_name='gobgpapi.AddPathCapability.tuples', index=0,
|
||||
number=1, type=11, cpp_type=10, label=3,
|
||||
has_default_value=False, default_value=[],
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=702,
|
||||
serialized_end=771,
|
||||
)
|
||||
|
||||
|
||||
_ENHANCEDROUTEREFRESHCAPABILITY = _descriptor.Descriptor(
|
||||
name='EnhancedRouteRefreshCapability',
|
||||
full_name='gobgpapi.EnhancedRouteRefreshCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=773,
|
||||
serialized_end=805,
|
||||
)
|
||||
|
||||
|
||||
_LONGLIVEDGRACEFULRESTARTCAPABILITYTUPLE = _descriptor.Descriptor(
|
||||
name='LongLivedGracefulRestartCapabilityTuple',
|
||||
full_name='gobgpapi.LongLivedGracefulRestartCapabilityTuple',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='family', full_name='gobgpapi.LongLivedGracefulRestartCapabilityTuple.family', index=0,
|
||||
number=1, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='flags', full_name='gobgpapi.LongLivedGracefulRestartCapabilityTuple.flags', index=1,
|
||||
number=2, type=13, cpp_type=3, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='time', full_name='gobgpapi.LongLivedGracefulRestartCapabilityTuple.time', index=2,
|
||||
number=3, type=13, cpp_type=3, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=807,
|
||||
serialized_end=911,
|
||||
)
|
||||
|
||||
|
||||
_LONGLIVEDGRACEFULRESTARTCAPABILITY = _descriptor.Descriptor(
|
||||
name='LongLivedGracefulRestartCapability',
|
||||
full_name='gobgpapi.LongLivedGracefulRestartCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='tuples', full_name='gobgpapi.LongLivedGracefulRestartCapability.tuples', index=0,
|
||||
number=1, type=11, cpp_type=10, label=3,
|
||||
has_default_value=False, default_value=[],
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=913,
|
||||
serialized_end=1016,
|
||||
)
|
||||
|
||||
|
||||
_ROUTEREFRESHCISCOCAPABILITY = _descriptor.Descriptor(
|
||||
name='RouteRefreshCiscoCapability',
|
||||
full_name='gobgpapi.RouteRefreshCiscoCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=1018,
|
||||
serialized_end=1047,
|
||||
)
|
||||
|
||||
|
||||
_UNKNOWNCAPABILITY = _descriptor.Descriptor(
|
||||
name='UnknownCapability',
|
||||
full_name='gobgpapi.UnknownCapability',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='code', full_name='gobgpapi.UnknownCapability.code', index=0,
|
||||
number=1, type=13, cpp_type=3, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='value', full_name='gobgpapi.UnknownCapability.value', index=1,
|
||||
number=2, type=12, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=b"",
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto3',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=1049,
|
||||
serialized_end=1097,
|
||||
)
|
||||
|
||||
_MULTIPROTOCOLCAPABILITY.fields_by_name['family'].message_type = gobgp__pb2._FAMILY
|
||||
_EXTENDEDNEXTHOPCAPABILITYTUPLE.fields_by_name['nlri_family'].message_type = gobgp__pb2._FAMILY
|
||||
_EXTENDEDNEXTHOPCAPABILITYTUPLE.fields_by_name['nexthop_family'].message_type = gobgp__pb2._FAMILY
|
||||
_EXTENDEDNEXTHOPCAPABILITY.fields_by_name['tuples'].message_type = _EXTENDEDNEXTHOPCAPABILITYTUPLE
|
||||
_GRACEFULRESTARTCAPABILITYTUPLE.fields_by_name['family'].message_type = gobgp__pb2._FAMILY
|
||||
_GRACEFULRESTARTCAPABILITY.fields_by_name['tuples'].message_type = _GRACEFULRESTARTCAPABILITYTUPLE
|
||||
_ADDPATHCAPABILITYTUPLE.fields_by_name['family'].message_type = gobgp__pb2._FAMILY
|
||||
_ADDPATHCAPABILITYTUPLE.fields_by_name['mode'].enum_type = _ADDPATHMODE
|
||||
_ADDPATHCAPABILITY.fields_by_name['tuples'].message_type = _ADDPATHCAPABILITYTUPLE
|
||||
_LONGLIVEDGRACEFULRESTARTCAPABILITYTUPLE.fields_by_name['family'].message_type = gobgp__pb2._FAMILY
|
||||
_LONGLIVEDGRACEFULRESTARTCAPABILITY.fields_by_name['tuples'].message_type = _LONGLIVEDGRACEFULRESTARTCAPABILITYTUPLE
|
||||
DESCRIPTOR.message_types_by_name['MultiProtocolCapability'] = _MULTIPROTOCOLCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['RouteRefreshCapability'] = _ROUTEREFRESHCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['CarryingLabelInfoCapability'] = _CARRYINGLABELINFOCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['ExtendedNexthopCapabilityTuple'] = _EXTENDEDNEXTHOPCAPABILITYTUPLE
|
||||
DESCRIPTOR.message_types_by_name['ExtendedNexthopCapability'] = _EXTENDEDNEXTHOPCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['GracefulRestartCapabilityTuple'] = _GRACEFULRESTARTCAPABILITYTUPLE
|
||||
DESCRIPTOR.message_types_by_name['GracefulRestartCapability'] = _GRACEFULRESTARTCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['FourOctetASNumberCapability'] = _FOUROCTETASNUMBERCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['AddPathCapabilityTuple'] = _ADDPATHCAPABILITYTUPLE
|
||||
DESCRIPTOR.message_types_by_name['AddPathCapability'] = _ADDPATHCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['EnhancedRouteRefreshCapability'] = _ENHANCEDROUTEREFRESHCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['LongLivedGracefulRestartCapabilityTuple'] = _LONGLIVEDGRACEFULRESTARTCAPABILITYTUPLE
|
||||
DESCRIPTOR.message_types_by_name['LongLivedGracefulRestartCapability'] = _LONGLIVEDGRACEFULRESTARTCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['RouteRefreshCiscoCapability'] = _ROUTEREFRESHCISCOCAPABILITY
|
||||
DESCRIPTOR.message_types_by_name['UnknownCapability'] = _UNKNOWNCAPABILITY
|
||||
DESCRIPTOR.enum_types_by_name['AddPathMode'] = _ADDPATHMODE
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
MultiProtocolCapability = _reflection.GeneratedProtocolMessageType('MultiProtocolCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _MULTIPROTOCOLCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.MultiProtocolCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(MultiProtocolCapability)
|
||||
|
||||
RouteRefreshCapability = _reflection.GeneratedProtocolMessageType('RouteRefreshCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ROUTEREFRESHCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.RouteRefreshCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(RouteRefreshCapability)
|
||||
|
||||
CarryingLabelInfoCapability = _reflection.GeneratedProtocolMessageType('CarryingLabelInfoCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _CARRYINGLABELINFOCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.CarryingLabelInfoCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(CarryingLabelInfoCapability)
|
||||
|
||||
ExtendedNexthopCapabilityTuple = _reflection.GeneratedProtocolMessageType('ExtendedNexthopCapabilityTuple', (_message.Message,), {
|
||||
'DESCRIPTOR' : _EXTENDEDNEXTHOPCAPABILITYTUPLE,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.ExtendedNexthopCapabilityTuple)
|
||||
})
|
||||
_sym_db.RegisterMessage(ExtendedNexthopCapabilityTuple)
|
||||
|
||||
ExtendedNexthopCapability = _reflection.GeneratedProtocolMessageType('ExtendedNexthopCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _EXTENDEDNEXTHOPCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.ExtendedNexthopCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(ExtendedNexthopCapability)
|
||||
|
||||
GracefulRestartCapabilityTuple = _reflection.GeneratedProtocolMessageType('GracefulRestartCapabilityTuple', (_message.Message,), {
|
||||
'DESCRIPTOR' : _GRACEFULRESTARTCAPABILITYTUPLE,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.GracefulRestartCapabilityTuple)
|
||||
})
|
||||
_sym_db.RegisterMessage(GracefulRestartCapabilityTuple)
|
||||
|
||||
GracefulRestartCapability = _reflection.GeneratedProtocolMessageType('GracefulRestartCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _GRACEFULRESTARTCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.GracefulRestartCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(GracefulRestartCapability)
|
||||
|
||||
FourOctetASNumberCapability = _reflection.GeneratedProtocolMessageType('FourOctetASNumberCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _FOUROCTETASNUMBERCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.FourOctetASNumberCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(FourOctetASNumberCapability)
|
||||
|
||||
AddPathCapabilityTuple = _reflection.GeneratedProtocolMessageType('AddPathCapabilityTuple', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ADDPATHCAPABILITYTUPLE,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.AddPathCapabilityTuple)
|
||||
})
|
||||
_sym_db.RegisterMessage(AddPathCapabilityTuple)
|
||||
|
||||
AddPathCapability = _reflection.GeneratedProtocolMessageType('AddPathCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ADDPATHCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.AddPathCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(AddPathCapability)
|
||||
|
||||
EnhancedRouteRefreshCapability = _reflection.GeneratedProtocolMessageType('EnhancedRouteRefreshCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ENHANCEDROUTEREFRESHCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.EnhancedRouteRefreshCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(EnhancedRouteRefreshCapability)
|
||||
|
||||
LongLivedGracefulRestartCapabilityTuple = _reflection.GeneratedProtocolMessageType('LongLivedGracefulRestartCapabilityTuple', (_message.Message,), {
|
||||
'DESCRIPTOR' : _LONGLIVEDGRACEFULRESTARTCAPABILITYTUPLE,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.LongLivedGracefulRestartCapabilityTuple)
|
||||
})
|
||||
_sym_db.RegisterMessage(LongLivedGracefulRestartCapabilityTuple)
|
||||
|
||||
LongLivedGracefulRestartCapability = _reflection.GeneratedProtocolMessageType('LongLivedGracefulRestartCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _LONGLIVEDGRACEFULRESTARTCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.LongLivedGracefulRestartCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(LongLivedGracefulRestartCapability)
|
||||
|
||||
RouteRefreshCiscoCapability = _reflection.GeneratedProtocolMessageType('RouteRefreshCiscoCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ROUTEREFRESHCISCOCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.RouteRefreshCiscoCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(RouteRefreshCiscoCapability)
|
||||
|
||||
UnknownCapability = _reflection.GeneratedProtocolMessageType('UnknownCapability', (_message.Message,), {
|
||||
'DESCRIPTOR' : _UNKNOWNCAPABILITY,
|
||||
'__module__' : 'capability_pb2'
|
||||
# @@protoc_insertion_point(class_scope:gobgpapi.UnknownCapability)
|
||||
})
|
||||
_sym_db.RegisterMessage(UnknownCapability)
|
||||
|
||||
|
||||
# @@protoc_insertion_point(module_scope)
|
|
@ -0,0 +1,3 @@
|
|||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
||||
import grpc
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.25 on 2020-05-31 00:00
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bgpdata', '0016_auto_20170117_0103'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='confighost',
|
||||
name='checkMethod',
|
||||
field=models.CharField(choices=[('CMK', 'Check MK'), ('PLAIN', 'Plain'), ('GOBGP', 'GoBGP')], max_length=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='crawllog',
|
||||
name='severity',
|
||||
field=models.CharField(choices=[('INFO', 'info'), ('ERROR', 'error'), ('DEBUG', 'debug'), ('WARN', 'warning')], max_length=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='peering',
|
||||
name='origin',
|
||||
field=models.CharField(choices=[('path', 'BGP Path'), ('direct', 'Direct Connection')], max_length=10),
|
||||
),
|
||||
]
|
|
@ -11,13 +11,14 @@ class ConfigHost(models.Model):
|
|||
CHECK_CHOICES = (
|
||||
('CMK', "Check MK"),
|
||||
('PLAIN', "Plain"),
|
||||
('GOBGP', "GoBGP"),
|
||||
)
|
||||
|
||||
# asno, ip, check method,
|
||||
name = models.CharField(max_length=50)
|
||||
number = models.IntegerField()
|
||||
ip = models.GenericIPAddressField()
|
||||
checkMethod = models.CharField(max_length=4, choices=CHECK_CHOICES)
|
||||
checkMethod = models.CharField(max_length=10, choices=CHECK_CHOICES)
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%s / %s)" % (self.name, self.number, self.ip)
|
||||
|
|
182
bin/crawl.py
182
bin/crawl.py
|
@ -1,13 +1,10 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python
|
||||
# This file is part of dnmapper, an AS--level mapping tool
|
||||
# Licensed under GNU General Public License v3 or later
|
||||
# Written by Sebastian Lohff (seba@someserver.de)
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
# config
|
||||
LAST_SEEN_DAYS = 7
|
||||
|
||||
# prepare environment
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
|
@ -23,6 +20,10 @@ from django.db.models import Q, Max
|
|||
|
||||
from bgpdata.models import ConfigHost, CrawlRun, CrawlLog, AS, BorderRouter, Announcement, Peering, BorderRouterPair
|
||||
from routerparsers import getBGPData, RouterParserException
|
||||
from backend import gobgp
|
||||
|
||||
# config
|
||||
LAST_SEEN_DAYS = 7
|
||||
|
||||
|
||||
def getOrCreateAS(crawl, number, online=True):
|
||||
|
@ -52,7 +53,9 @@ def main():
|
|||
print(" -- Getting data for host %s" % host)
|
||||
try:
|
||||
if host.checkMethod == 'CMK':
|
||||
data = getBGPData(host.ip, host.number)
|
||||
data = [getBGPData(host.ip, host.number)]
|
||||
elif host.checkMethod == 'GOBGP':
|
||||
data = gobgp.get_bgp_data(host.ip)
|
||||
else:
|
||||
CrawlLog.log(crawl, "Method %s is not currently supported, skipping host" % host.checkMethod, host=host, severity=CrawlLog.ERROR)
|
||||
continue
|
||||
|
@ -67,82 +70,8 @@ def main():
|
|||
CrawlLog.log(crawl, msg, host=host, severity=CrawlLog.ERROR)
|
||||
continue
|
||||
|
||||
print(" -- parsing...")
|
||||
|
||||
currASno = int(data["local_as"])
|
||||
currAS = getOrCreateAS(crawl, currASno)
|
||||
|
||||
currAS.directlyCrawled = True
|
||||
currAS.save()
|
||||
|
||||
currRouter = None
|
||||
try:
|
||||
currRouter = BorderRouter.objects.get(AS=currAS, routerID=data["local_id"])
|
||||
currRouter.pingable = True
|
||||
currRouter.reachable = True
|
||||
currRouter.save()
|
||||
except BorderRouter.DoesNotExist:
|
||||
currRouter = BorderRouter(AS=currAS, routerID=data["local_id"], pingable=True, reachable=True)
|
||||
currRouter.save()
|
||||
|
||||
print(" --> peers")
|
||||
for peer in data["peers"]:
|
||||
# peerings
|
||||
# data: BGP{state, neighbor_id, neighbor_as}, description
|
||||
|
||||
# a) find/create neighbor
|
||||
print(" ----> Peer:", int(peer["BGP"]["neighbor_as"]))
|
||||
neighAS = getOrCreateAS(crawl, int(peer["BGP"]["neighbor_as"]), online=peer["BGP"]["online"])
|
||||
|
||||
# b) find out if a peering already exists (maybe where we only need to add our router id?)
|
||||
peering = None
|
||||
try:
|
||||
peering = Peering.getPeering(currAS, neighAS)
|
||||
except Peering.DoesNotExist:
|
||||
peering = Peering(as1=currAS, as2=neighAS, origin=Peering.DIRECT)
|
||||
peering.save()
|
||||
|
||||
# c) look for router/peering pairs
|
||||
if peer["BGP"]["neighbor_id"]:
|
||||
try:
|
||||
neighRouter = BorderRouter.objects.get(AS=neighAS, routerID=peer["BGP"]["neighbor_id"])
|
||||
except BorderRouter.DoesNotExist:
|
||||
neighRouter = BorderRouter(AS=neighAS, routerID=peer["BGP"]["neighbor_id"], pingable=False, reachable=False)
|
||||
neighRouter.save()
|
||||
try:
|
||||
BorderRouterPair.getPairing(peering, currRouter, neighRouter)
|
||||
except BorderRouterPair.DoesNotExist:
|
||||
pairs = BorderRouterPair.objects.filter(Q(peering=peering) & (Q(router1=neighRouter, router2=None)|Q(router1=None, router2=neighRouter)))
|
||||
if pairs.count() > 0:
|
||||
pair = pairs[0]
|
||||
if pair.router1 == None:
|
||||
pair.router1 = currRouter
|
||||
else:
|
||||
pair.router2 = currRouter
|
||||
pair.save()
|
||||
else:
|
||||
pair = BorderRouterPair(peering=peering, router1=currRouter, router2=neighRouter)
|
||||
pair.save()
|
||||
|
||||
print(" --> Announcements")
|
||||
if "routes" in data and data["routes"]:
|
||||
for route in data["routes"]:
|
||||
print(" ---->", route["prefix"])
|
||||
if "/" not in route["prefix"]:
|
||||
continue
|
||||
|
||||
crawlAS = currAS
|
||||
if len(route["path"]) > 0:
|
||||
crawlAS = getOrCreateAS(crawl, route["path"][0])
|
||||
originAS = getOrCreateAS(crawl, route["path"][-1])
|
||||
ip, prefix = route["prefix"].split("/")
|
||||
a = Announcement(router=currRouter, ip=ip, prefix=prefix,
|
||||
ASPath=" ".join(route["path"]), nextHop=route["nexthop"],
|
||||
crawlAS=crawlAS, originAS=originAS)
|
||||
a.save()
|
||||
else:
|
||||
print(" !! No routes found in host output")
|
||||
CrawlLog.log(crawl, "No routes found in host output (no bgp feed included?)", host=host, severity=CrawlLog.WARN)
|
||||
for elem in data:
|
||||
parseData(crawl, host, elem)
|
||||
|
||||
# 3. calculate missing data
|
||||
print(" -- Adding extra data from announcements...")
|
||||
|
@ -168,7 +97,8 @@ def main():
|
|||
# find
|
||||
print(" --> copy old ASses")
|
||||
timerangeStart = crawl.startTime - datetime.timedelta(LAST_SEEN_DAYS)
|
||||
oldASses = AS.objects.filter(online=True, crawl__startTime__gte=timerangeStart).values("number").annotate(lastSeen=Max('crawl_id')).filter(~Q(lastSeen=crawl.pk))
|
||||
oldASses = AS.objects.filter(online=True, crawl__startTime__gte=timerangeStart) \
|
||||
.values("number").annotate(lastSeen=Max('crawl_id')).filter(~Q(lastSeen=crawl.pk))
|
||||
|
||||
# 3.2.1. copy old asses
|
||||
print(" ----> create ASses")
|
||||
|
@ -181,7 +111,7 @@ def main():
|
|||
if not newAS.online and not newAS.lastSeen:
|
||||
newAS.lastSeen = oldAS.crawl
|
||||
newAS.save()
|
||||
except:
|
||||
except Exception:
|
||||
newAS = AS(number=oldAS.number, crawl=crawl, lastSeen=oldAS.crawl, directlyCrawled=False, online=False)
|
||||
newAS.save()
|
||||
|
||||
|
@ -208,11 +138,95 @@ def main():
|
|||
crawl.asCount = crawl.as_set.count()
|
||||
crawl.asOnlineCount = crawl.as_set.filter(online=True).count()
|
||||
crawl.asOfflineCount = crawl.as_set.filter(online=False).count()
|
||||
crawl.peeringCount = Peering.objects.filter(Q(as1__crawl=crawl)|Q(as2__crawl=crawl)).count()
|
||||
crawl.peeringCount = Peering.objects.filter(Q(as1__crawl=crawl) | Q(as2__crawl=crawl)).count()
|
||||
crawl.save()
|
||||
|
||||
print(" !! Done")
|
||||
CrawlLog.log(crawl, "Crawl completed", severity=CrawlLog.INFO)
|
||||
|
||||
|
||||
def parseData(crawl, host, data):
|
||||
print(" -- parsing...")
|
||||
|
||||
currASno = int(data["local_as"])
|
||||
currAS = getOrCreateAS(crawl, currASno)
|
||||
|
||||
currAS.directlyCrawled = True
|
||||
currAS.save()
|
||||
|
||||
currRouter = None
|
||||
try:
|
||||
currRouter = BorderRouter.objects.get(AS=currAS, routerID=data["local_id"])
|
||||
currRouter.pingable = True
|
||||
currRouter.reachable = True
|
||||
currRouter.save()
|
||||
except BorderRouter.DoesNotExist:
|
||||
currRouter = BorderRouter(AS=currAS, routerID=data["local_id"], pingable=True, reachable=True)
|
||||
currRouter.save()
|
||||
|
||||
print(" --> peers")
|
||||
for peer in data["peers"]:
|
||||
# peerings
|
||||
# data: BGP{state, neighbor_id, neighbor_as}, description
|
||||
|
||||
# a) find/create neighbor
|
||||
print(" ----> Peer:", int(peer["BGP"]["neighbor_as"]))
|
||||
neighAS = getOrCreateAS(crawl, int(peer["BGP"]["neighbor_as"]), online=peer["BGP"]["online"])
|
||||
|
||||
# b) find out if a peering already exists (maybe where we only need to add our router id?)
|
||||
peering = None
|
||||
try:
|
||||
peering = Peering.getPeering(currAS, neighAS)
|
||||
except Peering.DoesNotExist:
|
||||
peering = Peering(as1=currAS, as2=neighAS, origin=Peering.DIRECT)
|
||||
peering.save()
|
||||
|
||||
# c) look for router/peering pairs
|
||||
if peer["BGP"]["neighbor_id"]:
|
||||
try:
|
||||
neighRouter = BorderRouter.objects.get(AS=neighAS, routerID=peer["BGP"]["neighbor_id"])
|
||||
except BorderRouter.DoesNotExist:
|
||||
neighRouter = BorderRouter(AS=neighAS, routerID=peer["BGP"]["neighbor_id"],
|
||||
pingable=False, reachable=False)
|
||||
neighRouter.save()
|
||||
try:
|
||||
BorderRouterPair.getPairing(peering, currRouter, neighRouter)
|
||||
except BorderRouterPair.DoesNotExist:
|
||||
pairs = BorderRouterPair.objects.filter(Q(peering=peering) & (Q(router1=neighRouter, router2=None) |
|
||||
Q(router1=None, router2=neighRouter)))
|
||||
if pairs.count() > 0:
|
||||
pair = pairs[0]
|
||||
if pair.router1 is None:
|
||||
pair.router1 = currRouter
|
||||
else:
|
||||
pair.router2 = currRouter
|
||||
pair.save()
|
||||
else:
|
||||
pair = BorderRouterPair(peering=peering, router1=currRouter, router2=neighRouter)
|
||||
pair.save()
|
||||
|
||||
print(" --> Announcements")
|
||||
if "routes" in data and data["routes"]:
|
||||
for route in data["routes"]:
|
||||
print(" ---->", route["prefix"])
|
||||
if "/" not in route["prefix"]:
|
||||
continue
|
||||
|
||||
crawlAS = currAS
|
||||
if len(route["path"]) > 0:
|
||||
route["path"] = list(map(str, route["path"]))
|
||||
crawlAS = getOrCreateAS(crawl, route["path"][0])
|
||||
originAS = getOrCreateAS(crawl, route["path"][-1])
|
||||
ip, prefix = route["prefix"].split("/")
|
||||
a = Announcement(router=currRouter, ip=ip, prefix=prefix,
|
||||
ASPath=" ".join(route["path"]), nextHop=route["nexthop"],
|
||||
crawlAS=crawlAS, originAS=originAS)
|
||||
a.save()
|
||||
else:
|
||||
print(" !! No routes found in host output")
|
||||
CrawlLog.log(crawl, "No routes found in host output (no bgp feed included?)",
|
||||
host=host, severity=CrawlLog.WARN)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue