blob: a884882c75a8c6e2eaeea339b22067e43b84cdb0 [file] [log] [blame]
Davide Scano555617a2020-06-03 21:47:13 +02001/*
2 * Copyright 2020-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, OnInit, OnDestroy} from '@angular/core';
17import { FormBuilder, FormGroup, FormArray, FormControl, Validators } from '@angular/forms';
18
19import {
20 FnService,
21 LogService,
22 WebSocketService,
23 SortDir, TableBaseImpl, TableResponse,
24} from 'org_onosproject_onos/web/gui2-fw-lib/public_api';
25
26import {ActivatedRoute, Router} from '@angular/router';
27
28// constants
29const intIntentAddReq = 'intIntentAddRequest';
30const intIntentDelReq = 'intIntentDelRequest';
Yi Tsengc4f90a52020-10-04 22:33:22 -070031const regSendIp = '^([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/[0-9]{1,2})?$'
Davide Scano555617a2020-06-03 21:47:13 +020032const regSendPort ='^[0-9]{0,5}$'
33
34export interface Metadata {
35 name: string;
36 value: string;
37}
38
39/**
40 * ONOS GUI -- INT App View Component
41 */
42@Component({
43 selector: 'int-app',
44 templateUrl: './intapp.component.html',
45 styleUrls: ['./intapp.component.css',
46 '../../../../../../web/gui2-fw-lib/lib/widget/table.css',
47 '../../../../../../web/gui2-fw-lib/lib/widget/table.theme.css'
48 ]
49})
50export class IntAppComponent extends TableBaseImpl implements OnInit, OnDestroy {
51
52 formConf: FormGroup;
53 formSend: FormGroup;
54 metaData: Metadata[] = [
55 { name: 'Switch ID', value : 'SWITCH_ID'},
56 { name: 'Port IDs', value:'PORT_ID' },
57 { name: 'Hop Latency', value: 'HOP_LATENCY', },
58 { name: 'Queue Occupancy', value:'QUEUE_OCCUPANCY' },
59 { name: 'Ingress Timestamp', value:'INGRESS_TIMESTAMP' },
60 { name: 'Egress Timestamp', value: 'EGRESS_TIMESTAMP' },
61 { name: 'Egress Port Tx Utilization', value:'EGRESS_TX_UTIL' },
62 ];
63
64 constructor(
65 protected fs: FnService,
66 protected log: LogService,
67 protected as: ActivatedRoute,
68 protected router: Router,
69 protected wss: WebSocketService,
70 protected fb: FormBuilder,
71 ) {
72 super(fs, log, wss, 'intAppIntIntent');
73
74 }
75
76 ngOnInit() {
77 this.init();
78 this.formSend = this.fb.group({
79 name: this.fb.array([]),
80 ip4SrcPrefix: new FormControl(null, [Validators.required, Validators.pattern(regSendIp)]),
81 ip4DstPrefix: new FormControl(null, [Validators.required, Validators.pattern(regSendIp)]),
82 l4SrcPort: new FormControl(null, [ Validators.pattern(regSendPort)]),
83 l4DstPort: new FormControl(null, [ Validators.pattern(regSendPort)]),
84 protocol: new FormControl(),
Yi Tsengd14f1a32020-10-13 19:15:12 -070085 telemetryMode: new FormControl("POSTCARD")
Davide Scano555617a2020-06-03 21:47:13 +020086 });
Davide Scano555617a2020-06-03 21:47:13 +020087 this.log.debug('IntAppComponent initialized');
88 }
89
90 ngOnDestroy() {
91 this.destroy();
92 this.log.debug('IntAppComponent destroyed');
93 }
94
95 navto(path) {
96 this.log.debug('navigate');
97 if (this.selId) {
98 this.router.navigate([path], {queryParams: {itemId: this.selId}});
99 }
100 }
101
102 onCheckboxChange(name: string, isChecked: boolean) {
103 this.log.debug('event'+ isChecked);
104 const meta = (this.formSend.controls.name as FormArray);
105
106 if (isChecked) {
107 meta.push(new FormControl(name));
108 } else {
109 const index = meta.controls.findIndex(x => x.value === name);
110 meta.removeAt(index);
111 }
112 }
113
Davide Scano555617a2020-06-03 21:47:13 +0200114 sendIntIntentString() {
115 if (this.formSend.invalid) {
116 return;
117 }
118 let intentObjectNode = {
119 "ip4SrcPrefix": this.formSend.value.ip4SrcPrefix,
120 "ip4DstPrefix": this.formSend.value.ip4DstPrefix,
121 "l4SrcPort": this.formSend.value.l4SrcPort,
122 "l4DstPort": this.formSend.value.l4DstPort,
123 "protocol": this.formSend.value.protocol,
Yi Tsengd14f1a32020-10-13 19:15:12 -0700124 "metadata": this.formSend.value.name,
125 "telemetryMode": this.formSend.value.telemetryMode
Davide Scano555617a2020-06-03 21:47:13 +0200126 };
127 this.wss.sendEvent(intIntentAddReq, intentObjectNode);
128 }
129
130 delIntIntent(){
131 if (this.selId) {
132 this.wss.sendEvent(intIntentDelReq,{"intentId": this.selId});
133 }
134 }
135}