blob: e026e1ca6aa12605771a9ad02342ef00f0302ba3 [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 { WebSocketService } from '../../../fw/remote/websocket.service';
19import { LogService } from '../../../log.service';
20import { LoadingService } from '../../../fw/layer/loading.service';
21import { FnService } from '../../../fw/util/fn.service';
22import { ActivatedRoute } from '@angular/router';
23
24/**
25* Model of the response from WebSocket
26*/
27interface MeterTableResponse extends TableResponse {
28 meters: Meter[];
29}
30
31/**
32* Model of the meter returned from the WebSocket
33*/
34interface Meter {
35 id: string;
36 appId: string;
37 state: string;
38 packets: string;
39 bytes: string;
40}
41
42/**
43 * ONOS GUI -- Meter View Component
44 */
45@Component({
46 selector: 'onos-meter',
47 templateUrl: './meter.component.html',
48 styleUrls: ['./meter.component.css', './meter.theme.css',
49 '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
50})
51export class MeterComponent extends TableBaseImpl implements OnInit, OnDestroy {
52
53 id: string;
54 brief: boolean = true;
55
56 // TODO: Update for LION
57 deviceTip = 'Show device table';
58 detailTip = 'Switch to detail view';
59 flowTip = 'Show flow view for selected device';
60 portTip = 'Show port view for selected device';
61 groupTip = 'Show group view for selected device';
62 pipeconfTip = 'Show pipeconf view for selected device';
63
64 constructor(
65 protected fs: FnService,
66 protected log: LogService,
67 protected ls: LoadingService,
68 protected as: ActivatedRoute,
69 protected wss: WebSocketService,
70 ) {
71 super(fs, ls, log, wss, 'meter');
72 this.as.queryParams.subscribe(params => {
73 this.id = params['devId'];
74 });
75
76 this.payloadParams = {
77 devId: this.id
78 };
79
80 this.responseCallback = this.meterResponseCb;
81 this.sortParams = {
82 firstCol: 'id',
83 firstDir: SortDir.desc,
84 secondCol: 'app_id',
85 secondDir: SortDir.asc,
86 };
87 }
88
89 ngOnInit() {
90 this.init();
91 this.log.debug('MeterComponent initialized');
92 }
93
94 ngOnDestroy() {
95 this.destroy();
96 this.log.debug('MeterComponent destroyed');
97 }
98
99 meterResponseCb(data: MeterTableResponse) {
100 this.log.debug('Meter response received for ', data.meters.length, 'meter');
101 }
102
103 briefToggle() {
104 this.brief = !this.brief;
105 }
106
107}