Jian Li | 7564231 | 2017-01-19 14:23:05 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | 7564231 | 2017-01-19 14:23:05 -0800 | [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 | */ |
| 16 | package org.onosproject.mapping; |
| 17 | |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 18 | import org.onosproject.net.DeviceId; |
Jian Li | 95edb59 | 2017-01-29 08:42:07 +0900 | [diff] [blame] | 19 | import org.onosproject.store.Store; |
| 20 | |
Jian Li | 7564231 | 2017-01-19 14:23:05 -0800 | [diff] [blame] | 21 | /** |
| 22 | * Interface of a distributed store for managing mapping information. |
| 23 | */ |
Jian Li | 95edb59 | 2017-01-29 08:42:07 +0900 | [diff] [blame] | 24 | public interface MappingStore extends Store<MappingEvent, MappingStoreDelegate> { |
Jian Li | c7badf9 | 2017-02-02 19:43:46 +0900 | [diff] [blame] | 25 | |
Jian Li | cc169f3 | 2017-02-24 20:13:23 +0900 | [diff] [blame] | 26 | /** |
| 27 | * Represents the type of mapping store. |
| 28 | */ |
Jian Li | c7badf9 | 2017-02-02 19:43:46 +0900 | [diff] [blame] | 29 | enum Type { |
| 30 | |
| 31 | /** |
| 32 | * Signifies that mapping information should be stored in map database. |
| 33 | */ |
| 34 | MAP_DATABASE, |
| 35 | |
| 36 | /** |
| 37 | * Signifies that mapping information should be stored in map cache. |
| 38 | */ |
| 39 | MAP_CACHE |
| 40 | } |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Obtains the number of mapping in the specified store. |
| 44 | * |
| 45 | * @param type store type |
| 46 | * @return number of mapping |
| 47 | */ |
| 48 | int getMappingCount(Type type); |
| 49 | |
| 50 | /** |
Jian Li | 791dd32 | 2017-04-20 00:15:56 +0900 | [diff] [blame] | 51 | * Obtains all mapping entries from the specified store. |
| 52 | * |
| 53 | * @param type store type |
| 54 | * @return the mapping entries |
| 55 | */ |
| 56 | Iterable<MappingEntry> getAllMappingEntries(Type type); |
| 57 | |
| 58 | /** |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 59 | * Obtains the stored mapping from the specified store. |
| 60 | * |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 61 | * @param type store type |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 62 | * @param mapping the mapping to look for |
| 63 | * @return a mapping |
| 64 | */ |
| 65 | MappingEntry getMappingEntry(Type type, Mapping mapping); |
| 66 | |
| 67 | /** |
| 68 | * Obtains the mapping entries associated with a device from the |
| 69 | * specified store. |
| 70 | * |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 71 | * @param type store type |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 72 | * @param deviceId device identifier |
| 73 | * @return the mapping entries |
| 74 | */ |
| 75 | Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId); |
| 76 | |
| 77 | /** |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 78 | * Stores a new mapping. |
| 79 | * |
| 80 | * @param type store type |
| 81 | * @param mapping the mapping to add |
| 82 | */ |
Jian Li | a1f960b | 2017-04-25 19:12:53 +0900 | [diff] [blame] | 83 | void storeMapping(Type type, MappingEntry mapping); |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 84 | |
| 85 | /** |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 86 | * Marks a mapping for deletion. Actual deletion will occur when the |
| 87 | * provider indicates that the mapping has been removed. |
| 88 | * |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 89 | * @param type store type |
Jian Li | 2dc9f00 | 2017-03-03 04:26:31 +0900 | [diff] [blame] | 90 | * @param mapping the mapping to be marked as delete |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 91 | */ |
Jian Li | 2dc9f00 | 2017-03-03 04:26:31 +0900 | [diff] [blame] | 92 | void pendingDeleteMapping(Type type, Mapping mapping); |
| 93 | |
| 94 | /** |
| 95 | * Removes an existing mapping from the specified store. |
| 96 | * |
| 97 | * @param type store type |
| 98 | * @param mapping the mapping to remove |
| 99 | * @return mapping_removed event, or null if nothing removed |
| 100 | */ |
| 101 | MappingEvent removeMapping(Type type, Mapping mapping); |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Stores a new mapping or updates an existing entry from/to the |
| 105 | * specified store. |
| 106 | * |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 107 | * @param type store type |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 108 | * @param entry the mapping to add or update |
| 109 | * @return mapping_added event, or null if just an update |
| 110 | */ |
| 111 | MappingEvent addOrUpdateMappingEntry(Type type, MappingEntry entry); |
| 112 | |
| 113 | /** |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 114 | * Marks a mapping as PENDING_ADD during retry. |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 115 | * <p> |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 116 | * Emits mapping_update event if the state is changed |
| 117 | * |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 118 | * @param type store type |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 119 | * @param entry the mapping that is retrying |
| 120 | * @return mapping_updated event, or null if nothing updated |
| 121 | */ |
| 122 | MappingEvent pendingMappingEntry(Type type, MappingEntry entry); |
| 123 | |
| 124 | /** |
| 125 | * Removes all mapping entries of given device from the specified store. |
| 126 | * |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 127 | * @param type store type |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 128 | * @param deviceId device identifier |
| 129 | */ |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 130 | default void purgeMappingEntry(Type type, DeviceId deviceId) { |
| 131 | } |
Jian Li | 9291959 | 2017-02-27 17:10:47 +0900 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * Removes all mapping entries from the specified store. |
| 135 | * |
| 136 | * @param type store type |
| 137 | */ |
| 138 | void purgeMappingEntries(Type type); |
Jian Li | 7564231 | 2017-01-19 14:23:05 -0800 | [diff] [blame] | 139 | } |