Now with announcements being displayed!

This commit is contained in:
Sebastian Lohff 2017-01-18 00:19:36 +01:00
parent 626f9fcf5d
commit 5d5e7999c3
6 changed files with 80 additions and 6 deletions

View File

@ -32,5 +32,5 @@ class AnnouncementResource(ModelResource):
class Meta: class Meta:
list_allowed_methods = ['get'] list_allowed_methods = ['get']
detail_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() queryset = Announcement.objects.all()

View File

@ -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,
),
]

View File

@ -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,
),
]

View File

@ -105,6 +105,9 @@ class AS(models.Model):
def getPeerings(self): def getPeerings(self):
return Peering.objects.filter(Q(as1=self)|Q(as2=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): def formatLastSeen(self):
if self.lastSeen: if self.lastSeen:
return self.lastSeen.startTime.strftime("%d.%m.%Y %H:%I") return self.lastSeen.startTime.strftime("%d.%m.%Y %H:%I")
@ -132,7 +135,8 @@ class Announcement(models.Model):
# NOTE: increase length for longer pathes (currently supports a length of ~85) # NOTE: increase length for longer pathes (currently supports a length of ~85)
ASPath = models.CharField(max_length=512) ASPath = models.CharField(max_length=512)
nextHop = models.GenericIPAddressField() 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): def __unicode__(self):
return u"%s/%s via %s (crawl %s)" % (self.ip, self.prefix, self.ASPath, self.router.AS.crawl.pk) return u"%s/%s via %s (crawl %s)" % (self.ip, self.prefix, self.ASPath, self.router.AS.crawl.pk)

View File

@ -25,7 +25,7 @@
var asdata = [ var asdata = [
{% for AS in ASses %} {% 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%} {%endfor%}
]; ];
@ -172,6 +172,11 @@ $('svg g').tipsy({
if(d.crawled) { if(d.crawled) {
content += '<tr><th>Note</th><td>Directly crawled</td></tr>'; 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>'; content += '</table>';
//(function(node) { //(function(node) {

View File

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