Jian Li | 7564231 | 2017-01-19 14:23:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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 | /** |
| 51 | * Obtains the stored mapping from the specified store. |
| 52 | * |
| 53 | * @param type store type |
| 54 | * @param mapping the mapping to look for |
| 55 | * @return a mapping |
| 56 | */ |
| 57 | MappingEntry getMappingEntry(Type type, Mapping mapping); |
| 58 | |
| 59 | /** |
| 60 | * Obtains the mapping entries associated with a device from the |
| 61 | * specified store. |
| 62 | * |
| 63 | * @param type store type |
| 64 | * @param deviceId device identifier |
| 65 | * @return the mapping entries |
| 66 | */ |
| 67 | Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId); |
| 68 | |
| 69 | /** |
| 70 | * Marks a mapping for deletion. Actual deletion will occur when the |
| 71 | * provider indicates that the mapping has been removed. |
| 72 | * |
| 73 | * @param type store type |
| 74 | * @param mapping the mapping to delete |
| 75 | */ |
| 76 | void deleteMapping(Type type, Mapping mapping); |
| 77 | |
| 78 | /** |
| 79 | * Stores a new mapping or updates an existing entry from/to the |
| 80 | * specified store. |
| 81 | * |
| 82 | * @param type store type |
| 83 | * @param entry the mapping to add or update |
| 84 | * @return mapping_added event, or null if just an update |
| 85 | */ |
| 86 | MappingEvent addOrUpdateMappingEntry(Type type, MappingEntry entry); |
| 87 | |
| 88 | /** |
| 89 | * Removes an existing mapping from the specified store. |
| 90 | * |
| 91 | * @param type store type |
| 92 | * @param entry the mapping to remove |
| 93 | * @return mapping_removed event, or null if nothing removed |
| 94 | */ |
| 95 | MappingEvent removeMappingEntry(Type type, MappingEntry entry); |
| 96 | |
| 97 | /** |
| 98 | * Marks a mapping as PENDING_ADD during retry. |
| 99 | * |
| 100 | * Emits mapping_update event if the state is changed |
| 101 | * |
| 102 | * @param type store type |
| 103 | * @param entry the mapping that is retrying |
| 104 | * @return mapping_updated event, or null if nothing updated |
| 105 | */ |
| 106 | MappingEvent pendingMappingEntry(Type type, MappingEntry entry); |
| 107 | |
| 108 | /** |
| 109 | * Removes all mapping entries of given device from the specified store. |
| 110 | * |
| 111 | * @param type store type |
| 112 | * @param deviceId device identifier |
| 113 | */ |
| 114 | default void purgeMappingEntry(Type type, DeviceId deviceId) {} |
| 115 | |
| 116 | /** |
| 117 | * Removes all mapping entries from the specified store. |
| 118 | * |
| 119 | * @param type store type |
| 120 | */ |
| 121 | void purgeMappingEntries(Type type); |
Jian Li | 7564231 | 2017-01-19 14:23:05 -0800 | [diff] [blame] | 122 | } |