blob: 1c86c9c56c43b23905e53cb54a80713cab82a458 [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';
17import { SortDir, TableBaseImpl, TableResponse } from '../../../fw/widget/table.base';
18import { FnService } from '../../../fw/util/fn.service';
19import { LoadingService } from '../../../fw/layer/loading.service';
20import { LogService } from '../../../log.service';
21import { ActivatedRoute } from '@angular/router';
22import { WebSocketService } from '../../../fw/remote/websocket.service';
23import { PrefsService } from '../../../fw/util/prefs.service';
24
25/**
26 * Model of the response from WebSocket
27 */
28interface PortTableResponse extends TableResponse {
29 ports: Port[];
30}
31
32/**
33 * Model of the ports returned from the WebSocket
34 */
35interface Port {
36 id: string;
37 pktsRecieved: string;
38 pktsSent: string;
39 byteRecieved: string;
40 byteSent: string;
41 pktsRxDropped: string;
42 pktsTxDropped: string;
43 duration: string;
44}
45
46interface FilterToggleState {
47 devId: string;
48 nzFilter: boolean;
49 showDelta: boolean;
50}
51
52const defaultPortPrefsState = {
53 nzFilter: 1,
54 showDelta: 0,
55};
56
57/**
58 * ONOS GUI -- Port View Component
59 */
60@Component({
61 selector: 'onos-port',
62 templateUrl: './port.component.html',
63 styleUrls: ['./port.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
64})
65export class PortComponent extends TableBaseImpl implements OnInit, OnDestroy {
66 devId: string;
67 nzFilter: boolean = true;
68 showDelta: boolean = false;
69 prefsState = {};
70 toggleState: FilterToggleState;
71
72 restorePrefsConfig; // Function
73
74 deviceTip = 'Show device table';
75 flowTip = 'Show flow view for this device';
76 groupTip = 'Show group view for this device';
77 meterTip = 'Show meter view for selected device';
78 pipeconfTip = 'Show pipeconf view for selected device';
79 toggleDeltaTip = 'Toggle port delta statistics';
80 toggleNZTip = 'Toggle non zero port statistics';
81
82 constructor(protected fs: FnService,
83 protected ls: LoadingService,
84 protected log: LogService,
85 protected ar: ActivatedRoute,
86 protected wss: WebSocketService,
87 protected prefs: PrefsService,
88 ) {
89 super(fs, ls, log, wss, 'port');
90 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}