Browse Source

Now with announcements being displayed!

master
Sebastian Lohff 6 years ago
parent
commit
5d5e7999c3
  1. 2
      bgpdata/api.py
  2. 44
      bgpdata/migrations/0015_auto_20170117_0034.py
  3. 20
      bgpdata/migrations/0016_auto_20170117_0103.py
  4. 6
      bgpdata/models.py
  5. 7
      bgpdata/templates/bgpdata/map.html
  6. 7
      bin/crawl.py

2
bgpdata/api.py

@ -32,5 +32,5 @@ class AnnouncementResource(ModelResource): @@ -32,5 +32,5 @@ class AnnouncementResource(ModelResource):
class Meta:
list_allowed_methods = ['get']
detail_allowed_methods = ['get']
filtering = {'originAS': ALL_WITH_RELATIONS, 'router': ALL_WITH_RELATIONS}
filtering = {'originAS': ALL_WITH_RELATIONS, 'crawlAS': ALL_WITH_RELATIONS, 'router': ALL_WITH_RELATIONS}
queryset = Announcement.objects.all()

44
bgpdata/migrations/0015_auto_20170117_0034.py

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('bgpdata', '0014_auto_20170113_2022'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='crawlAS',
field=models.ForeignKey(related_name='crawl_as', to='bgpdata.AS', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='crawlrun',
name='asCount',
field=models.IntegerField(default=0),
preserve_default=True,
),
migrations.AlterField(
model_name='crawlrun',
name='asOfflineCount',
field=models.IntegerField(default=0),
preserve_default=True,
),
migrations.AlterField(
model_name='crawlrun',
name='asOnlineCount',
field=models.IntegerField(default=0),
preserve_default=True,
),
migrations.AlterField(
model_name='crawlrun',
name='peeringCount',
field=models.IntegerField(default=0),
preserve_default=True,
),
]

20
bgpdata/migrations/0016_auto_20170117_0103.py

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('bgpdata', '0015_auto_20170117_0034'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='originAS',
field=models.ForeignKey(to='bgpdata.AS', null=True),
preserve_default=True,
),
]

6
bgpdata/models.py

@ -105,6 +105,9 @@ class AS(models.Model): @@ -105,6 +105,9 @@ class AS(models.Model):
def getPeerings(self):
return Peering.objects.filter(Q(as1=self)|Q(as2=self))
def getAnnouncedPrefixes(self):
return list(set(map(lambda _x: "%(ip)s/%(prefix)s" % _x, self.announcement_set.all().values('ip', 'prefix'))))
def formatLastSeen(self):
if self.lastSeen:
return self.lastSeen.startTime.strftime("%d.%m.%Y %H:%I")
@ -132,7 +135,8 @@ class Announcement(models.Model): @@ -132,7 +135,8 @@ class Announcement(models.Model):
# NOTE: increase length for longer pathes (currently supports a length of ~85)
ASPath = models.CharField(max_length=512)
nextHop = models.GenericIPAddressField()
originAS = models.ForeignKey(AS)
originAS = models.ForeignKey(AS, null=True)
crawlAS = models.ForeignKey(AS, related_name='crawl_as', null=True)
def __unicode__(self):
return u"%s/%s via %s (crawl %s)" % (self.ip, self.prefix, self.ASPath, self.router.AS.crawl.pk)

7
bgpdata/templates/bgpdata/map.html

@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
var asdata = [
{% for AS in ASses %}
{id: {{AS.pk}}, nodetype: "AS", asnumber: {{AS.number}}, label: "{{AS.number}}", neighbors: {{AS.getPeerings.count}}, crawled: {%if AS.directlyCrawled%}true{%else%}false{%endif%}, online: {%if AS.online%}true{%else%}false{%endif%}, lastSeenDate: "{{AS.formatLastSeen}}", lastSeen: {%if AS.lastSeen%}{{AS.lastSeen.pk}}{%else%}null{%endif%}, dismiss: true}{%if not forloop.last%},{%endif%}
{id: {{AS.pk}}, nodetype: "AS", asnumber: {{AS.number}}, label: "{{AS.number}}", neighbors: {{AS.getPeerings.count}}, crawled: {%if AS.directlyCrawled%}true{%else%}false{%endif%}, online: {%if AS.online%}true{%else%}false{%endif%}, lastSeenDate: "{{AS.formatLastSeen}}", lastSeen: {%if AS.lastSeen%}{{AS.lastSeen.pk}}{%else%}null{%endif%}, dismiss: true, announcements: [{% for a in AS.getAnnouncedPrefixes %}"{{a}}"{%if not forloop.last%},{%endif%}{%endfor%}]}{%if not forloop.last%},{%endif%}
{%endfor%}
];
@ -172,6 +172,11 @@ $('svg g').tipsy({ @@ -172,6 +172,11 @@ $('svg g').tipsy({
if(d.crawled) {
content += '<tr><th>Note</th><td>Directly crawled</td></tr>';
}
if(d.announcements.length > 0) {
content += '<tr><th>Netw.</th><td>';
content += d.announcements.join(", ")
content += '</td></tr>';
}
content += '</table>';
//(function(node) {

7
bin/crawl.py

@ -127,13 +127,14 @@ def main(): @@ -127,13 +127,14 @@ def main():
if "/" not in route["prefix"]:
continue
originAS = currAS
crawlAS = currAS
if len(route["path"]) > 0:
originAS = getOrCreateAS(crawl, 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"],
originAS=originAS)
crawlAS=crawlAS, originAS=originAS)
a.save()
else:
print(" !! No routes found in host output")

Loading…
Cancel
Save