blob: e2d6109f7043813c9d6ae5ecdaeddf0c5ac61771 [file] [log] [blame]
Jian Li75642312017-01-19 14:23:05 -08001/*
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 */
16package org.onosproject.mapping;
17
Jian Li92919592017-02-27 17:10:47 +090018import org.onosproject.net.DeviceId;
Jian Li95edb592017-01-29 08:42:07 +090019import org.onosproject.store.Store;
20
Jian Li75642312017-01-19 14:23:05 -080021/**
22 * Interface of a distributed store for managing mapping information.
23 */
Jian Li95edb592017-01-29 08:42:07 +090024public interface MappingStore extends Store<MappingEvent, MappingStoreDelegate> {
Jian Lic7badf92017-02-02 19:43:46 +090025
Jian Licc169f32017-02-24 20:13:23 +090026 /**
27 * Represents the type of mapping store.
28 */
Jian Lic7badf92017-02-02 19:43:46 +090029 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 Li92919592017-02-27 17:10:47 +090041
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 *
Jian Li252750d2017-03-01 04:50:13 +090053 * @param type store type
Jian Li92919592017-02-27 17:10:47 +090054 * @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 *
Jian Li252750d2017-03-01 04:50:13 +090063 * @param type store type
Jian Li92919592017-02-27 17:10:47 +090064 * @param deviceId device identifier
65 * @return the mapping entries
66 */
67 Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId);
68
69 /**
Jian Li252750d2017-03-01 04:50:13 +090070 * Stores a new mapping.
71 *
72 * @param type store type
73 * @param mapping the mapping to add
74 */
75 void storeMapping(Type type, Mapping mapping);
76
77 /**
Jian Li92919592017-02-27 17:10:47 +090078 * Marks a mapping for deletion. Actual deletion will occur when the
79 * provider indicates that the mapping has been removed.
80 *
Jian Li252750d2017-03-01 04:50:13 +090081 * @param type store type
Jian Li2dc9f002017-03-03 04:26:31 +090082 * @param mapping the mapping to be marked as delete
Jian Li92919592017-02-27 17:10:47 +090083 */
Jian Li2dc9f002017-03-03 04:26:31 +090084 void pendingDeleteMapping(Type type, Mapping mapping);
85
86 /**
87 * Removes an existing mapping from the specified store.
88 *
89 * @param type store type
90 * @param mapping the mapping to remove
91 * @return mapping_removed event, or null if nothing removed
92 */
93 MappingEvent removeMapping(Type type, Mapping mapping);
Jian Li92919592017-02-27 17:10:47 +090094
95 /**
96 * Stores a new mapping or updates an existing entry from/to the
97 * specified store.
98 *
Jian Li252750d2017-03-01 04:50:13 +090099 * @param type store type
Jian Li92919592017-02-27 17:10:47 +0900100 * @param entry the mapping to add or update
101 * @return mapping_added event, or null if just an update
102 */
103 MappingEvent addOrUpdateMappingEntry(Type type, MappingEntry entry);
104
105 /**
Jian Li92919592017-02-27 17:10:47 +0900106 * Marks a mapping as PENDING_ADD during retry.
Jian Li252750d2017-03-01 04:50:13 +0900107 * <p>
Jian Li92919592017-02-27 17:10:47 +0900108 * Emits mapping_update event if the state is changed
109 *
Jian Li252750d2017-03-01 04:50:13 +0900110 * @param type store type
Jian Li92919592017-02-27 17:10:47 +0900111 * @param entry the mapping that is retrying
112 * @return mapping_updated event, or null if nothing updated
113 */
114 MappingEvent pendingMappingEntry(Type type, MappingEntry entry);
115
116 /**
117 * Removes all mapping entries of given device from the specified store.
118 *
Jian Li252750d2017-03-01 04:50:13 +0900119 * @param type store type
Jian Li92919592017-02-27 17:10:47 +0900120 * @param deviceId device identifier
121 */
Jian Li252750d2017-03-01 04:50:13 +0900122 default void purgeMappingEntry(Type type, DeviceId deviceId) {
123 }
Jian Li92919592017-02-27 17:10:47 +0900124
125 /**
126 * Removes all mapping entries from the specified store.
127 *
128 * @param type store type
129 */
130 void purgeMappingEntries(Type type);
Jian Li75642312017-01-19 14:23:05 -0800131}