blob: 1c66459c74b2ad7eaf920314931099cac7bab054 [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,
Sean Condon5ca00262018-09-06 17:55:25 +010019 LogService,
20 PrefsService,
21 WebSocketService,
22 SortDir, TableBaseImpl, TableResponse
23} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053024import { ActivatedRoute } from '@angular/router';
Bhavesh72ead492018-07-19 16:29:18 +053025
26/**
27 * Model of the response from WebSocket
28 */
29interface PortTableResponse extends TableResponse {
30 ports: Port[];
31}
32
33/**
34 * Model of the ports returned from the WebSocket
35 */
36interface Port {
37 id: string;
38 pktsRecieved: string;
39 pktsSent: string;
40 byteRecieved: string;
41 byteSent: string;
42 pktsRxDropped: string;
43 pktsTxDropped: string;
44 duration: string;
45}
46
47interface FilterToggleState {
48 devId: string;
49 nzFilter: boolean;
50 showDelta: boolean;
51}
52
53const defaultPortPrefsState = {
54 nzFilter: 1,
55 showDelta: 0,
56};
57
58/**
59 * ONOS GUI -- Port View Component
60 */
61@Component({
62 selector: 'onos-port',
63 templateUrl: './port.component.html',
64 styleUrls: ['./port.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
65})
66export class PortComponent extends TableBaseImpl implements OnInit, OnDestroy {
67 devId: string;
68 nzFilter: boolean = true;
69 showDelta: boolean = false;
70 prefsState = {};
71 toggleState: FilterToggleState;
72
73 restorePrefsConfig; // Function
74
75 deviceTip = 'Show device table';
76 flowTip = 'Show flow view for this device';
77 groupTip = 'Show group view for this device';
78 meterTip = 'Show meter view for selected device';
79 pipeconfTip = 'Show pipeconf view for selected device';
80 toggleDeltaTip = 'Toggle port delta statistics';
81 toggleNZTip = 'Toggle non zero port statistics';
82
83 constructor(protected fs: FnService,
Bhavesh72ead492018-07-19 16:29:18 +053084 protected log: LogService,
85 protected ar: ActivatedRoute,
86 protected wss: WebSocketService,
87 protected prefs: PrefsService,
88 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010089 super(fs, log, wss, 'port');
Bhavesh72ead492018-07-19 16:29:18 +053090 this.ar.queryParams.subscribe(params => {
91 this.devId = params['devId'];
92
93 });
94
95 this.payloadParams = {
96 devId: this.devId
97 };
98
99 this.responseCallback = this.portResponseCb;
100 this.restorePrefsConfig = this.restoreConfigFromPrefs;
101
102 this.sortParams = {
103 firstCol: 'id',
104 firstDir: SortDir.desc,
105 secondCol: 'pkt_rx',
106 secondDir: SortDir.asc,
107 };
108 }
109
110 ngOnInit() {
111 this.init();
112 this.log.debug('PortComponent initialized');
113 }
114
115 ngOnDestroy() {
116 this.destroy();
117 this.log.debug('PortComponent destroyed');
118 }
119
120 portResponseCb(data: PortTableResponse) {
121 this.log.debug('Port response received for ', data.ports.length, 'port');
122 }
123
124 isNz(): boolean {
125 return this.nzFilter;
126 }
127
128 isDelta(): boolean {
129 return this.showDelta;
130 }
131
132 toggleNZState(b?: any) {
133 if (b === undefined) {
134 this.nzFilter = !this.nzFilter;
135 } else {
136 this.nzFilter = b;
137 }
138 this.payloadParams = this.filterToggleState();
139 this.updatePrefsState('nzFilter', this.nzFilter);
140 this.forceRefesh();
141 }
142
143 toggleDeltaState(b?: any) {
144 if (b === undefined) {
145 this.showDelta = !this.showDelta;
146 } else {
147 this.showDelta = b;
148 }
149
150 this.payloadParams = this.filterToggleState();
151 this.updatePrefsState('showDelta', this.showDelta);
152 this.forceRefesh();
153 }
154
155 updatePrefsState(what: any, b: any) {
156 this.prefsState[what] = b ? 1 : 0;
157 this.prefs.setPrefs('port_prefs', this.prefsState);
158 }
159
160 filterToggleState(): FilterToggleState {
161 return this.toggleState = {
162 devId: this.devId,
163 nzFilter: this.nzFilter,
164 showDelta: this.showDelta,
165 };
166 }
167
168 forceRefesh() {
169 this.requestTableData();
170 }
171
172 restoreConfigFromPrefs() {
173 this.prefsState = this.prefs.asNumbers(
174 this.prefs.getPrefs('port_prefs', defaultPortPrefsState, )
175 );
176
177 this.log.debug('Port - Prefs State:', this.prefsState);
178 this.toggleDeltaState(this.prefsState['showDelta']);
179 this.toggleNZState(this.prefsState['nzFilter']);
180 }
181
182}