updates to account for links to network nodes and recreating them, ignoring recreated edges

This commit is contained in:
Blake J. Harnden 2018-05-07 16:08:38 -07:00
parent 8e99af96a4
commit bf05fe0b9b

View file

@ -1,6 +1,7 @@
const Ip4Prefix = '10.0.0.1/24'; const Ip4Prefix = '10.0.0.1/24';
const Ip6Prefix = '2001::/64'; const Ip6Prefix = '2001::/64';
const DefaultNode = 0;
const PtpNode = 12; const PtpNode = 12;
const NodeTypes = { const NodeTypes = {
// default router // default router
@ -195,7 +196,9 @@ class CoreNetwork {
const toNode = this.nodes.get(linkData.node2_id).coreNode; const toNode = this.nodes.get(linkData.node2_id).coreNode;
const linkId = `${fromNode.id}-${toNode.id}`; const linkId = `${fromNode.id}-${toNode.id}`;
const interfaceOne = { let interfaceOne = null;
if (linkData.interface1_id !== null) {
interfaceOne = {
id: linkData.interface1_id, id: linkData.interface1_id,
ip4: linkData.interface1_ip4, ip4: linkData.interface1_ip4,
ip4mask: linkData.interface1_ip4_mask, ip4mask: linkData.interface1_ip4_mask,
@ -203,8 +206,11 @@ class CoreNetwork {
ip6mask: linkData.interface1_ip6_mask ip6mask: linkData.interface1_ip6_mask
}; };
fromNode.interfaces[linkData.interface1_id] = interfaceOne; fromNode.interfaces[linkData.interface1_id] = interfaceOne;
}
const interfaceTwo = { let interfaceTwo = null;
if (linkData.interface2_id !== null) {
interfaceTwo = {
id: linkData.interface2_id, id: linkData.interface2_id,
ip4: linkData.interface2_ip4, ip4: linkData.interface2_ip4,
ip4mask: linkData.interface2_ip4_mask, ip4mask: linkData.interface2_ip4_mask,
@ -212,6 +218,7 @@ class CoreNetwork {
ip6mask: linkData.interface2_ip6_mask ip6mask: linkData.interface2_ip6_mask
}; };
toNode.interfaces[linkData.interface2_id] = interfaceTwo; toNode.interfaces[linkData.interface2_id] = interfaceTwo;
}
this.links[linkId] = { this.links[linkId] = {
node_one: fromNode.id, node_one: fromNode.id,
@ -220,7 +227,7 @@ class CoreNetwork {
interface_two: interfaceTwo interface_two: interfaceTwo
}; };
const edge = {from: fromNode.id, to: toNode.id}; const edge = {from: fromNode.id, to: toNode.id, recreated: true};
this.edges.add(edge); this.edges.add(edge);
} }
@ -257,6 +264,12 @@ class CoreNetwork {
addEdge(_, properties) { addEdge(_, properties) {
const edgeId = properties.items[0]; const edgeId = properties.items[0];
const edge = this.edges.get(edgeId); const edge = this.edges.get(edgeId);
if (edge.recreated) {
console.log('ignoring recreated edge');
setTimeout(() => this.network.addEdgeMode(), 250);
return;
}
console.log('added edge: ', edgeId, edge); console.log('added edge: ', edgeId, edge);
if (edge.from === edge.to) { if (edge.from === edge.to) {
console.log('removing cyclic edge'); console.log('removing cyclic edge');
@ -274,18 +287,17 @@ class CoreNetwork {
console.log('create link error: ', err); console.log('create link error: ', err);
}); });
// keep edge mode enabled
setTimeout(() => this.network.addEdgeMode(), 250); setTimeout(() => this.network.addEdgeMode(), 250);
} }
async addEdgeLink(edge, fromNode, toNode) { async addEdgeLink(edge, fromNode, toNode) {
const fromIps = await this.coreRest.getNodeIps(fromNode.id, Ip4Prefix, Ip6Prefix);
const toIps = await this.coreRest.getNodeIps(toNode.id, Ip4Prefix, Ip6Prefix);
console.log('link ips: ', fromIps, toIps);
const linkId = `${fromNode.id}-${toNode.id}`; const linkId = `${fromNode.id}-${toNode.id}`;
const interfaceOneId =Object.keys(fromNode.interfaces).length; let interfaceOne = null;
const interfaceOne = { if (fromNode.type === DefaultNode) {
const fromIps = await this.coreRest.getNodeIps(fromNode.id, Ip4Prefix, Ip6Prefix);
console.log('from ips: ', fromIps);
const interfaceOneId = Object.keys(fromNode.interfaces).length;
interfaceOne = {
id: interfaceOneId, id: interfaceOneId,
ip4: fromIps.ip4, ip4: fromIps.ip4,
ip4mask: fromIps.ip4mask, ip4mask: fromIps.ip4mask,
@ -293,9 +305,14 @@ class CoreNetwork {
ip6mask: fromIps.ip6mask ip6mask: fromIps.ip6mask
}; };
fromNode.interfaces[interfaceOneId] = interfaceOne; fromNode.interfaces[interfaceOneId] = interfaceOne;
}
let interfaceTwo = null;
if (toNode.type === DefaultNode) {
const toIps = await this.coreRest.getNodeIps(toNode.id, Ip4Prefix, Ip6Prefix);
console.log('to ips: ', toIps);
const interfaceTwoId = Object.keys(toNode.interfaces).length; const interfaceTwoId = Object.keys(toNode.interfaces).length;
const interfaceTwo = { interfaceTwo = {
id: interfaceTwoId, id: interfaceTwoId,
ip4: toIps.ip4, ip4: toIps.ip4,
ip4mask: toIps.ip4mask, ip4mask: toIps.ip4mask,
@ -303,6 +320,7 @@ class CoreNetwork {
ip6mask: toIps.ip6mask ip6mask: toIps.ip6mask
}; };
toNode.interfaces[interfaceTwoId] = interfaceTwo; toNode.interfaces[interfaceTwoId] = interfaceTwo;
}
this.links[linkId] = { this.links[linkId] = {
node_one: fromNode.id, node_one: fromNode.id,