// register "font" icon
nx.graphic.Icons.registerFontIcon('devicedown', 'FontAwesome', "\uf057", 20);
+ var circle = "<defs xmlns='http://www.w3.org/2000/svg'><marker id='circle' viewBox='-3 -3 6 6' markerWidth='6' markerHeight='6' orient='auto'> <circle r='3' fill='#68BD6B'></circle></marker></defs>";
+
var app = new nx.ui.Application();
// set app containter
document.getElementById('graph-container').innerHTML = '';
app.container(document.getElementById('graph-container'));
+ scope.topo = NextTopologyService.getNxTopClass(scope.topoColors);
+ scope.setTopoEvents();
+ scope.topo.stage().addDefString(circle);
+
extendLinkClass();
extendNodeClass();
extendedTooltip();
//createNodeStatusLayer();
defineCustomEvents();
- scope.topo = NextTopologyService.getNxTopClass(scope.topoColors);
- scope.setTopoEvents();
+
// App events - if app is resized
app.on('resize', function(){
},
// when topology's updated
update: function(){
+ /*
this.inherited();
+
// ECMP badge settings
var badge = this.view('badge');
var badgeText = this.view('badgeText');
var badgeBg = this.view('badgeBg');
var statusIcon = this.view('statusIcon');
var status = this.model()._data.status;
+ ECMP, not needed here
if( this.model()._data.gLinks.length > 2 ) {
badgeText.sets({
text: status.operational + '/' + status.configured,
//set correct link color
this.set('color',this.getColor());
+ */
+ this.setProviderStyleLine();
},
// generate the color for a link
getColor: function(){
// make it available outside next
this.model()._data.linkColor = color;
return color;
- }
+ },
+
+ setProviderStyleLine: function() {
+ var _offset = this.getOffset();
+ var offset = new nx.geometry.Vector(0, _offset);
+ var stageScale = this.stageScale();
+ var line = this.reverse() ? this.line().negate() : this.line();
+ var lineEl = this.view('line');
+ var newLine = line.translate(offset).pad(25 * stageScale, stageScale);
+ lineEl.sets({
+ x1: newLine.start.x,
+ y1: newLine.start.y,
+ x2: newLine.end.x,
+ y2: newLine.end.y
+ });
+ lineEl.setStyle('marker-start', 'url(#circle)');
+ }
}
});
}
});
}
-
// TODO: remove when come to decision about depiction of node status
///**
// * Creating new node status layer - circles representing device status - up, down
NextTopology.$inject=['NextTopologyService'];
return NextTopology;
-});
\ No newline at end of file
+});
links: [],
};
+ $scope.resolvedPolicy = {};
+
$scope.cbkFunctions = {
clickNode: function(node){
var epg = EpgService.createObject();
// NextTopologyService.fadeInAllLayers();
},
clickLink: function(link){
- var contract = ContractService.createObject();
- contract.get(link['_data-id'], link['_model']['_data']['tenantId'], 'operational');
- contract.data.parentTenant = link['_model']['_data']['tenantId'];
- $scope.openSidePanel('resolved-policy/contract-sidepanel', contract, null);
+ //var contract = ContractService.createObject();
+ //contract.get(link['_model']['_data'].contract, link['_model']['_data'].tenant, 'operational');
+ //contract.data.parentTenant = link['_model']['_data'].tenant;
+ var resolvedContract = $scope.resolvedPolicy[link['_model']['_data'].id];
+ $scope.openSidePanel('resolved-policy/contract-sidepanel', resolvedContract, null);
$scope.$apply();
},
// topologyGenerated: function(){
function fillTopologyData() {
var topoData = {nodes: [], links: [],};
+
resolvedPolicies.data.forEach(function(rp) {
topoData.nodes.push(createNode(rp['consumer-epg-id'], rp['consumer-tenant-id']));
topoData.nodes.push(createNode(rp['provider-epg-id'], rp['provider-tenant-id']));
- // topoData.links.push(createLink(rp['policy-rule-group-with-endpoint-constraints'][0]['policy-rule-group'][0]['contract-id'], rp['consumer-epg-id'], rp['provider-epg-id']));
+
+ fillResolvedPolicy(rp);
+ topoData.links = getContracts(rp);
});
$scope.topologyData = topoData;
$scope.topologyLoaded = true;
}
+ function fillResolvedPolicy(data) {
+ if(data['policy-rule-group-with-endpoint-constraints']) {
+ processPolicyRuleGroupWithEpConstraints(
+ data['policy-rule-group-with-endpoint-constraints'],
+ data['provider-epg-id'],
+ data['consumer-epg-id']);
+ }
+
+ }
+
+ function processPolicyRuleGroupWithEpConstraints(data, providerEpgId, consumerEpgId) {
+ data.forEach(function(element) {
+ element['policy-rule-group'].forEach(function(el) {
+ var linkId = generateLinkId(el['contract-id'], providerEpgId, consumerEpgId);
+
+ if(!$scope.resolvedPolicy.hasOwnProperty(linkId)) {
+ $scope.resolvedPolicy[linkId] = {
+ 'contract-id': el['contract-id'],
+ 'subjects': {},
+ };
+ }
+
+ if(!$scope.resolvedPolicy[linkId].subjects.hasOwnProperty(el['subject-name'])) {
+ $scope.resolvedPolicy[linkId].subjects[el['subject-name']] = {'resolved-rule': []};
+ }
+
+ $scope.resolvedPolicy[linkId].subjects[el['subject-name']]['resolved-rule'].push(el['resolved-rule']);
+ })
+ })
+ }
+
+ function generateLinkId(contractId, providerEpgId, consumerEpgId) {
+ return contractId + '_' + providerEpgId + '_' + consumerEpgId;
+ }
+
function createNode(nodeName, tenantId) {
return {
'id': nodeName,
};
}
- function createLink(linkName, source, target) {
+ function createLink( source, target, contract, tenant) {
return {
- 'id' : linkName,
- 'source' : source,
- 'target' : target,
+ 'id': generateLinkId(contract, source, target),
+ 'source': source,
+ 'target': target,
+ 'tenant': tenant,
};
}
+
+ function getContracts(data) {
+ var retVal = [];
+
+ if( data['policy-rule-group-with-endpoint-constraints'] &&
+ data['policy-rule-group-with-endpoint-constraints'][0]['policy-rule-group']) {
+ data['policy-rule-group-with-endpoint-constraints'][0]['policy-rule-group'].forEach(function(prg) {
+ retVal.push(
+ createLink(
+ data['provider-epg-id'],
+ data['consumer-epg-id'],
+ prg['contract-id'],
+ prg['tenant-id']
+ )
+ )
+ });
+ }
+
+ return retVal;
+ }
}
});