blob: 7a6c89287b180b1ddba18a7623910b46273b6e11 [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 */
16
17import { Component, OnDestroy, OnInit } from '@angular/core';
Sean Condon5ca00262018-09-06 17:55:25 +010018import {
19 FnService,
20 LoadingService,
21 LogService,
22 WebSocketService,
23 LionService,
24 SortDir, TableBaseImpl, TableResponse
25} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053026import { ActivatedRoute } from '@angular/router';
Bhavesh72ead492018-07-19 16:29:18 +053027
28/**
29 * Model of the response from WebSocket
30 */
31interface FlowTableResponse extends TableResponse {
32 flows: Flow[];
33}
34
35/**
36 * Model of the flows returned from the WebSocket
37 */
38interface Flow {
39 state: string;
40 packets: string;
41 duration: string;
42 priority: string;
43 tableName: string;
44 selector: string;
45 treatment: string;
46 appName: string;
47}
48
49/**
50 * ONOS GUI -- Flow View Component
51 */
52@Component({
53 selector: 'onos-flow',
54 templateUrl: './flow.component.html',
55 styleUrls: ['./flow.component.css', './flow.theme.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
56})
57export class FlowComponent extends TableBaseImpl implements OnInit, OnDestroy {
58
59 lionFn; // Function
60 id: string;
61 brief: boolean;
62 selRowAppId: string;
63
64 deviceTip: string;
65 detailTip: string;
66 briefTip: string;
67 portTip: string;
68 groupTip: string;
69 meterTip: string;
70 pipeconfTip: string;
71
72 constructor(protected fs: FnService,
73 protected ls: LoadingService,
74 protected log: LogService,
75 protected as: ActivatedRoute,
76 protected wss: WebSocketService,
77 protected lion: LionService,
78 ) {
79 super(fs, ls, log, wss, 'flow');
80 this.as.queryParams.subscribe(params => {
81 this.id = params['devId'];
82
83 });
84 this.brief = true;
85
86 this.payloadParams = {
87 devId: this.id
88 };
89
90 this.responseCallback = this.flowResponseCb;
91
92 this.sortParams = {
93 firstCol: 'state',
94 firstDir: SortDir.desc,
95 secondCol: 'packets',
96 secondDir: SortDir.asc,
97 };
98
99 // We want doLion() to be called only after the Lion
100 // service is populated (from the WebSocket)
101 // If lion is not ready we make do with a dummy function
102 // As soon a lion gets loaded this function will be replaced with
103 // the real thing
104 if (this.lion.ubercache.length === 0) {
105 this.lionFn = this.dummyLion;
106 this.lion.loadCbs.set('flows', () => this.doLion());
107 } else {
108 this.doLion();
109 }
110
111 this.parentSelCb = this.rowSelection;
112 }
113
114 ngOnInit() {
115 this.init();
116 this.log.debug('FlowComponent initialized');
117 }
118
119 ngOnDestroy() {
120 this.lion.loadCbs.delete('flows');
121 this.destroy();
122 this.log.debug('FlowComponent destroyed');
123 }
124
125 flowResponseCb(data: FlowTableResponse) {
126 this.log.debug('Flow response received for ', data.flows.length, 'flow');
127 }
128
129 briefToggle() {
130 this.brief = !this.brief;
131 }
132
133 /**
134 * Read the LION bundle for App and set up the lionFn
135 */
136 doLion() {
137 this.lionFn = this.lion.bundle('core.view.Flow');
138
139 this.deviceTip = this.lionFn('tt_ctl_show_device');
140 this.detailTip = this.lionFn('tt_ctl_switcth_detailed');
141 this.briefTip = this.lionFn('tt_ctl_switcth_brief');
142 this.portTip = this.lionFn('tt_ctl_show_port');
143 this.groupTip = this.lionFn('tt_ctl_show_group');
144 this.meterTip = this.lionFn('tt_ctl_show_meter');
145 this.pipeconfTip = this.lionFn('tt_ctl_show_pipeconf');
146 }
147
148 rowSelection(event: any, selRow: any) {
149 this.selRowAppId = selRow.appId;
150 }
151
152}