summaryrefslogtreecommitdiffstats
path: root/vbd/gui/module/src/main/resources/vpp/services/vpp.services.js
blob: 70b1631f75774e1dc669e4d08b14df1f5a3c01a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
define(['app/vpp/vpp.module', 'next'], function(vpp) {

    vpp.register.factory('VPPRestangular', function(Restangular, ENV) {
        return Restangular.withConfig(function(RestangularConfig) {
            RestangularConfig.setBaseUrl(ENV.getBaseURL("MD_SAL"));
        });
    });

    vpp.register.factory('VPPRestangularXml', function(Restangular, ENV) {
        return Restangular.withConfig(function(RestangularConfig) {
            RestangularConfig.setBaseUrl(ENV.getBaseURL("MD_SAL"));
            RestangularConfig.setDefaultHeaders({ "Content-Type": "application/xml" }, { "Accept": "application/xml" });
        });
    });

    vpp.register.service('toastService', function($mdToast) {
        this.showToast = function(content) {
            var toast = $mdToast.simple()
                .content(content)
                .action('OK')
                .position('bottom right');
            $mdToast.show(toast);
        }
    });

    vpp.register.service('dataService', function() {

        nx.graphic.Icons.registerIcon("bd", "src/app/vpp/assets/images/bd1.svg", 45, 45);
        nx.graphic.Icons.registerIcon("interf", "src/app/vpp/assets/images/interf.svg", 45, 45);

        this.bridgeDomainsTopo = new nx.graphic.Topology({
            height: 350,
            width: 500,
            scalable: true,
            theme:'blue',
            enableGradualScaling:true,
            nodeConfig: {
                color: '#414040',
                label: 'model.label',
                scale: 'model.scale',
                iconType: function(vertex) {
                    var type = vertex.get().type;
                    if (type === 'bd') {
                        return 'bd'
                    } else if (type === 'vpp') {
                        return 'switch'
                    } else {
                        return 'interf';
                    }
                }
            },
            linkConfig: {
                label: 'model.label',
                linkType: 'parallel',
                color: function(link) {
                    if (link.getData().type === 'tunnel') {
                        return '#00FF00';
                    } else {
                        return '#414040';
                    }
                },
                width: function(link) {
                    if (link.getData().type === 'tunnel') {
                        return 5;
                    }
                }
            },
            showIcon: true,
            dataProcessor: 'force',
            autoLayout: true,
            enableSmartNode: false,
            tooltipManagerConfig: {
                nodeTooltipContentClass: 'TooltipNode',
                linkTooltipContentClass: 'TooltipLink'
            }
        });
        this.nextApp =  new nx.ui.Application;

        this.vpps = [];

        this.tableContent = [];
        this.unassignedInterfaces = [];
        this.interfaces = [];
        this.injectedInterfaces = [];
        this.bridgedomains = [];
        this.changedInterfaces = [];
        this.selectedBd = {
            name: ''
        };

        this.setBridgeDomains = function(data) {
            angular.copy(data['bridge-domains']['bridge-domain'], this.bridgedomains);
        };

        this.clearInjectedInterfacesInBridgeDomainTopo = function() {
            this.bridgeDomainsTopo.clear();
            this.injectedInterfaces.length = 0;

        };

        this.generateUnassignedInterfaces = function() {
            this.unassignedInterfaces.length = 0;
            for (var x=0; x<this.interfaces.length; x++) {
                if (!this.interfaces[x]['v3po:l2']['bridge-domain']) {
                    this.unassignedInterfaces.push(this.interfaces[x]);
                }
            }
        };

        this.injectBridgeDomainsTopoElements = function() {
            this.clearInjectedInterfacesInBridgeDomainTopo();
            this.injectBdIntoBridgeDomainsTopo();
            this.injectInterfacesIntoBridgeDomainsTopo();
            this.injectInterfacesLinksIntoBridgeDomainsTopo();
            this.bridgeDomainsTopo.adaptToContainer();
        };

        this.buildTableContent = function() {
            this.tableContent.length = 0;
            this.generateUnassignedInterfaces();
            angular.copy(this.unassignedInterfaces.concat(this.injectedInterfaces),this.tableContent);
        };

        this.injectBdIntoBridgeDomainsTopo = function() {
            this.bridgeDomainsTopo.addNode({
                name : this.selectedBd.name,
                label: this.selectedBd.name,
                x: 60,
                y: -50,
                scale: 5
            });
        };

        this.injectInterfacesLinksIntoBridgeDomainsTopo = function() {
            var nodes = this.bridgeDomainsTopo.getNodes();
            for (var x=1; x<nodes.length; x++){
                var target = nodes[x].get('data-id');
                this.bridgeDomainsTopo.addLink({'source':0, 'target': target});
            }
        };

        this.injectInterfacesIntoBridgeDomainsTopo = function() {
            for (var x=0; x<this.interfaces.length; x++) {
                if ((this.interfaces[x]['v3po:l2']['bridge-domain'] === this.selectedBd.name) && (this.interfaces[x].type==='iana-if-type:ethernetCsmacd')) {
                    this.interfaces[x].label = 'vpp1/'+this.interfaces[x].name;
                    this.bridgeDomainsTopo.addNode(this.interfaces[x]);
                    this.injectedInterfaces.push(this.interfaces[x]);
                    this.interfaces[x].assigned = true;
                }
            }
        };

    });



});