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