Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP space visualization module #59

Open
wants to merge 62 commits into
base: development
Choose a base branch
from
Open

IP space visualization module #59

wants to merge 62 commits into from

Conversation

rasovica
Copy link

@rasovica rasovica commented Jun 25, 2017

This module will add IP space map to nodewatcher, which will visualize and report statistics about network IP space usage.

@mitar
Copy link
Member

mitar commented Jun 25, 2017

In which way is this different from #58?

@kostko kostko changed the title WiP: Cidr module added WIP: CIDR module added Jun 25, 2017
rasovica added 4 commits June 27, 2017 06:12
…static folder, Mike Bostock is author of d3.v4, hilbert2d.js and point.js are refractored from node.js version to browser version by me, original author(https://github.com/ryan-williams), jquery.tips.js is made by https://github.com/jaz303 this modules provide all i need to draw svg maps with tooltips using hilbert fractals.
@@ -665,6 +666,11 @@ def user_url(user):
'weight': 60,
'visible': True,
},
{
'name': 'Ip space',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to "IP space".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -277,7 +277,7 @@ def import_pools(self, data):
pool_mdl = pool_models.IpPool(
family='ipv4',
network=pool['network'],
prefix_length=pool['cidr'],
prefix_length=pool['ip_space'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes in import_nw2.py seem incorrect - was this a too broad search and replace?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should not be touched from what I understand.
That is only used to import old Nodewatcher 2 JSON dump for migration

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

@kostko kostko Jun 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look fixed, there are still some incorrect ip_space references in import_nw2.py? See diff.

@robimarko
Copy link
Contributor

Please add some description so most people can at least get a sense of what you are doing here

@mitar mitar changed the title WIP: CIDR module added WIP: IP space module added Jun 27, 2017
@mitar
Copy link
Member

mitar commented Jun 27, 2017

Please put code attribution into code comments, not commit messages.

@mitar
Copy link
Member

mitar commented Jun 27, 2017

Don't use minimized JavaScript files. If we need those, we will just have minimization post-processing step for all files.


components.partials.get_partial('ip_space_partial').add(components.PartialEntry(
name='general',
template='ip_space.html',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok that the template is at the top level? I think it should be better to move it under network/ip_space/ip_space.html or similar.

Copy link
Member

@kostko kostko Jun 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see where these partials are currently used? Are they needed at all? If not, they should be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rasovica where are you using these partials?

@kostko
Copy link
Member

kostko commented Jun 29, 2017

BTW, please fix your GitHub or the commits' e-mail address as they don't seem to correspond (unknown author).

@@ -665,6 +666,11 @@ def user_url(user):
'weight': 60,
'visible': True,
},
{
'name': 'IP space',
'weight': 70,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be placed before the API entry instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put it before Map entry so it's next to network toplogoy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

self.loadedPrefixes++;
if(self.data[i] == undefined){
self.data[i] = data.results;
}else{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Into new line.

jQuery('rect').tipsy({
gravity: 'w',
html: true,
title: function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anonymous function, use function () { style.


load() {
for (var i = 0; i < 33; i++) {
this.loadPrefix(i, 'api/v2/pool/ip/?format=json&prefix_length=' + i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get URL API from server-side and render-it into a template. See examples elsewhere how to do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not have to add format=json because getJSON adds needed headers already.

range[0] = (this.ip2num(cidr[0])) & ((-1 << (32 - cidr_1)));
var start = this.ip2num(range[0])
range[1] = range[0] + Math.pow(2, (32 - cidr_1)) - 1;
return [range[0]-this.offset, range[1]-this.offset];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space around operators.

while( Math.pow(2, mask) < ips_needed){
mask++;
}
mask = 32-mask;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space around operators.

this.svg = svg;
this.loadedPrefixes = 0;

this.n_ips = Math.pow(2, 32 - parseInt(subnet.split("/")[1]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

' instead ". Please when I make a comment, make sure yourself to check everywhere else for the same issue.

this.ips_side = Math.sqrt(this.n_ips);
this.ips_pixel = this.ips_side / (this.size * 1.0);
this.offset = 0;
this.draw(subnet, "Smallest possible network to fit all the ip pools");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ip -> IP

this.data = new Array(33);
this.base_url = url;
self = this;
$('#topnodes').on('click', '#cidr', function(event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are already using class, so you can then also use (event) => { ... } which will bind this automatically so you do not have to use self.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, style for anonymous functions is function (event) {.

return false;
}

UpdateQueryString(key, value, url) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Camel case. Start with lower case.


subnetSize(subnet) {
var subnet_str = String(subnet);
var times = 32 - parseInt(subnet_str.split("/")[1]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'.

HSVtoRGB(h, s, v) {
var r, g, b, i, f, p, q, t;
if (arguments.length === 1) {
s = h.s, v = h.v, h = h.h;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split this into multiple lines. No ,.

t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
r = v, g = t, b = p;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

return '#' + this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);
}

get_url_param(sParam) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use camelCase not under_scores.


get_url_param(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ,. Simply define one var per line.

}

UpdateQueryString(key, value, url) {
if (!url){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after ).

else {
hash = url.split('#');
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No if without {...}.

hash = url.split('#');
url = hash[0] + separator + key + '=' + value;
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

url += '#' + hash[1];
return url;
}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.


loadPrefix(i, url) {
var self = this;
$.getJSON(url, function(data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use (data) => {...}.

$.getJSON(url, function(data) {
if(data.next != null){
self.loadPrefix(i, data.next);
if (self.data[i] == undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use ===.

loadPrefix(i, url) {
var self = this;
$.getJSON(url, function(data) {
if(data.next != null){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces. Always use !==.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants