slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 1 | /* |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 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 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 16 | package org.onosproject.artemis; |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onlab.packet.IpPrefix; |
| 19 | |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 20 | import java.util.Arrays; |
| 21 | import java.util.Optional; |
| 22 | |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 23 | /** |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 24 | * Interface for Monitors. |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 25 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 26 | public interface Monitors { |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Get prefix of the specific monitor. |
| 29 | * |
| 30 | * @return prefix |
| 31 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 32 | IpPrefix getPrefix(); |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Set prefix for monitor. |
| 36 | * |
| 37 | * @param prefix prefix |
| 38 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 39 | void setPrefix(IpPrefix prefix); |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Start monitor to begin capturing incoming BGP packets. |
| 43 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 44 | void startMonitor(); |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Stop monitor from capturing incoming BGP packets. |
| 48 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 49 | void stopMonitor(); |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Check if monitor is running. |
| 53 | * |
| 54 | * @return true if running |
| 55 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 56 | boolean isRunning(); |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Get host alias e.g. IP address, name. |
| 60 | * |
| 61 | * @return host alias |
| 62 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 63 | String getHost(); |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Set alias of host. |
| 67 | * |
| 68 | * @param host alias |
| 69 | */ |
Dimitrios Mavrommatis | f0c0632 | 2017-10-31 23:49:04 -0700 | [diff] [blame] | 70 | void setHost(String host); |
| 71 | |
| 72 | /** |
| 73 | * Match enum type with monitor type inside configuration to map them. |
| 74 | */ |
| 75 | enum Types { |
| 76 | RIPE("ripe") { |
| 77 | @Override |
| 78 | public String toString() { |
| 79 | return "ripe"; |
| 80 | } |
| 81 | }, |
| 82 | EXABGP("exabgp") { |
| 83 | @Override |
| 84 | public String toString() { |
| 85 | return "exabgp"; |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | private String name; |
| 90 | |
| 91 | Types(String name) { |
| 92 | this.name = name; |
| 93 | } |
| 94 | |
| 95 | public static Types getEnum(String name) { |
| 96 | Optional<Types> any = Arrays.stream(Types.values()).filter(typeStr -> typeStr.name.equals(name)).findAny(); |
| 97 | if (any.isPresent()) { |
| 98 | return any.get(); |
| 99 | } |
| 100 | throw new IllegalArgumentException("No enum defined for string: " + name); |
| 101 | } |
| 102 | } |
slowr | db071b2 | 2017-07-07 11:10:25 -0700 | [diff] [blame] | 103 | } |