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