blob: 96692a4302336a775fbb6507353a6ad1f9d4a089 [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';
18import { SortDir, TableBaseImpl, TableResponse } from '../../../fw/widget/table.base';
19import { WebSocketService } from '../../../fw/remote/websocket.service';
20import { LogService } from '../../../log.service';
21import { LoadingService } from '../../../fw/layer/loading.service';
22import { FnService } from '../../../fw/util/fn.service';
23import { ActivatedRoute } from '@angular/router';
24import { LionService } from '../../../fw/util/lion.service';
25
26
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',
54 styleUrls: ['./flow.component.css', './flow.theme.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
55})
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,
72 protected ls: LoadingService,
73 protected log: LogService,
74 protected as: ActivatedRoute,
75 protected wss: WebSocketService,
76 protected lion: LionService,
77 ) {
78 super(fs, ls, log, wss, 'flow');
79 this.as.queryParams.subscribe(params => {
80 this.id = params['devId'];
81
82 });
83 this.brief = true;
84
85 this.payloadParams = {
86 devId: this.id
87 };
88
89 this.responseCallback = this.flowResponseCb;
90
91 this.sortParams = {
92 firstCol: 'state',
93 firstDir: SortDir.desc,
94 secondCol: 'packets',
95 secondDir: SortDir.asc,
96 };
97
98 // We want doLion() to be called only after the Lion
99 // service is populated (from the WebSocket)
100 // If lion is not ready we make do with a dummy function
101 // As soon a lion gets loaded this function will be replaced with
102 // the real thing
103 if (this.lion.ubercache.length === 0) {
104 this.lionFn = this.dummyLion;
105 this.lion.loadCbs.set('flows', () => this.doLion());
106 } else {
107 this.doLion();
108 }
109
110 this.parentSelCb = this.rowSelection;
111 }
112
113 ngOnInit() {
114 this.init();
115 this.log.debug('FlowComponent initialized');
116 }
117
118 ngOnDestroy() {
119 this.lion.loadCbs.delete('flows');
120 this.destroy();
121 this.log.debug('FlowComponent destroyed');
122 }
123
124 flowResponseCb(data: FlowTableResponse) {
125 this.log.debug('Flow response received for ', data.flows.length, 'flow');
126 }
127
128 briefToggle() {
129 this.brief = !this.brief;
130 }
131
132 /**
133 * Read the LION bundle for App and set up the lionFn
134 */
135 doLion() {
136 this.lionFn = this.lion.bundle('core.view.Flow');
137
138 this.deviceTip = this.lionFn('tt_ctl_show_device');
139 this.detailTip = this.lionFn('tt_ctl_switcth_detailed');
140 this.briefTip = this.lionFn('tt_ctl_switcth_brief');
141 this.portTip = this.lionFn('tt_ctl_show_port');
142 this.groupTip = this.lionFn('tt_ctl_show_group');
143 this.meterTip = this.lionFn('tt_ctl_show_meter');
144 this.pipeconfTip = this.lionFn('tt_ctl_show_pipeconf');
145 }
146
147 rowSelection(event: any, selRow: any) {
148 this.selRowAppId = selRow.appId;
149 }
150
151}