blob: 0dcd11410d937bd8f3626954d9ab27d9abe99330 [file] [log] [blame]
Bhavesh72ead492018-07-19 16:29:18 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { Component, OnDestroy, OnInit } from '@angular/core';
Sean Condon5ca00262018-09-06 17:55:25 +010017import {
18 FnService,
19 LoadingService,
20 LogService,
21 PrefsService,
22 WebSocketService,
23 SortDir, TableBaseImpl, TableResponse
24} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053025import { ActivatedRoute } from '@angular/router';
Bhavesh72ead492018-07-19 16:29:18 +053026
27/**
28 * Model of the response from WebSocket
29 */
30interface PortTableResponse extends TableResponse {
31 ports: Port[];
32}
33
34/**
35 * Model of the ports returned from the WebSocket
36 */
37interface Port {
38 id: string;
39 pktsRecieved: string;
40 pktsSent: string;
41 byteRecieved: string;
42 byteSent: string;
43 pktsRxDropped: string;
44 pktsTxDropped: string;
45 duration: string;
46}
47
48interface FilterToggleState {
49 devId: string;
50 nzFilter: boolean;
51 showDelta: boolean;
52}
53
54const defaultPortPrefsState = {
55 nzFilter: 1,
56 showDelta: 0,
57};
58
59/**
60 * ONOS GUI -- Port View Component
61 */
62@Component({
63 selector: 'onos-port',
64 templateUrl: './port.component.html',
65 styleUrls: ['./port.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
66})
67export class PortComponent extends TableBaseImpl implements OnInit, OnDestroy {
68 devId: string;
69 nzFilter: boolean = true;
70 showDelta: boolean = false;
71 prefsState = {};
72 toggleState: FilterToggleState;
73
74 restorePrefsConfig; // Function
75
76 deviceTip = 'Show device table';
77 flowTip = 'Show flow view for this device';
78 groupTip = 'Show group view for this device';
79 meterTip = 'Show meter view for selected device';
80 pipeconfTip = 'Show pipeconf view for selected device';
81 toggleDeltaTip = 'Toggle port delta statistics';
82 toggleNZTip = 'Toggle non zero port statistics';
83
84 constructor(protected fs: FnService,
85 protected ls: LoadingService,
86 protected log: LogService,
87 protected ar: ActivatedRoute,
88 protected wss: WebSocketService,
89 protected prefs: PrefsService,
90 ) {
91 super(fs, ls, log, wss, 'port');
92 this.ar.queryParams.subscribe(params => {
93 this.devId = params['devId'];
94
95 });
96
97 this.payloadParams = {
98 devId: this.devId
99 };
100
101 this.responseCallback = this.portResponseCb;
102 this.restorePrefsConfig = this.restoreConfigFromPrefs;
103
104 this.sortParams = {
105 firstCol: 'id',
106 firstDir: SortDir.desc,
107 secondCol: 'pkt_rx',
108 secondDir: SortDir.asc,
109 };
110 }
111
112 ngOnInit() {
113 this.init();
114 this.log.debug('PortComponent initialized');
115 }
116
117 ngOnDestroy() {
118 this.destroy();
119 this.log.debug('PortComponent destroyed');
120 }
121
122 portResponseCb(data: PortTableResponse) {
123 this.log.debug('Port response received for ', data.ports.length, 'port');
124 }
125
126 isNz(): boolean {
127 return this.nzFilter;
128 }
129
130 isDelta(): boolean {
131 return this.showDelta;
132 }
133
134 toggleNZState(b?: any) {
135 if (b === undefined) {
136 this.nzFilter = !this.nzFilter;
137 } else {
138 this.nzFilter = b;
139 }
140 this.payloadParams = this.filterToggleState();
141 this.updatePrefsState('nzFilter', this.nzFilter);
142 this.forceRefesh();
143 }
144
145 toggleDeltaState(b?: any) {
146 if (b === undefined) {
147 this.showDelta = !this.showDelta;
148 } else {
149 this.showDelta = b;
150 }
151
152 this.payloadParams = this.filterToggleState();
153 this.updatePrefsState('showDelta', this.showDelta);
154 this.forceRefesh();
155 }
156
157 updatePrefsState(what: any, b: any) {
158 this.prefsState[what] = b ? 1 : 0;
159 this.prefs.setPrefs('port_prefs', this.prefsState);
160 }
161
162 filterToggleState(): FilterToggleState {
163 return this.toggleState = {
164 devId: this.devId,
165 nzFilter: this.nzFilter,
166 showDelta: this.showDelta,
167 };
168 }
169
170 forceRefesh() {
171 this.requestTableData();
172 }
173
174 restoreConfigFromPrefs() {
175 this.prefsState = this.prefs.asNumbers(
176 this.prefs.getPrefs('port_prefs', defaultPortPrefsState, )
177 );
178
179 this.log.debug('Port - Prefs State:', this.prefsState);
180 this.toggleDeltaState(this.prefsState['showDelta']);
181 this.toggleNZState(this.prefsState['nzFilter']);
182 }
183
184}