blob: b33f70e8a785f00ef488d04c3ab53ae8b6f1c75b [file] [log] [blame]
Jian Li75642312017-01-19 14:23:05 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li75642312017-01-19 14:23:05 -08003 *
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 /**
Jian Li791dd322017-04-20 00:15:56 +090051 * 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 Li92919592017-02-27 17:10:47 +090059 * Obtains the stored mapping from the specified store.
60 *
Jian Li252750d2017-03-01 04:50:13 +090061 * @param type store type
Jian Li92919592017-02-27 17:10:47 +090062 * @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 Li252750d2017-03-01 04:50:13 +090071 * @param type store type
Jian Li92919592017-02-27 17:10:47 +090072 * @param deviceId device identifier
73 * @return the mapping entries
74 */
75 Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId);
76
77 /**
Jian Li252750d2017-03-01 04:50:13 +090078 * Stores a new mapping.
79 *
80 * @param type store type
81 * @param mapping the mapping to add
82 */
Jian Lia1f960b2017-04-25 19:12:53 +090083 void storeMapping(Type type, MappingEntry mapping);
Jian Li252750d2017-03-01 04:50:13 +090084
85 /**
Jian Li92919592017-02-27 17:10:47 +090086 * Marks a mapping for deletion. Actual deletion will occur when the
87 * provider indicates that the mapping has been removed.
88 *
Jian Li252750d2017-03-01 04:50:13 +090089 * @param type store type
Jian Li2dc9f002017-03-03 04:26:31 +090090 * @param mapping the mapping to be marked as delete
Jian Li92919592017-02-27 17:10:47 +090091 */
Jian Li2dc9f002017-03-03 04:26:31 +090092 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 Li92919592017-02-27 17:10:47 +0900102
103 /**
104 * Stores a new mapping or updates an existing entry from/to the
105 * specified store.
106 *
Jian Li252750d2017-03-01 04:50:13 +0900107 * @param type store type
Jian Li92919592017-02-27 17:10:47 +0900108 * @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 Li92919592017-02-27 17:10:47 +0900114 * Marks a mapping as PENDING_ADD during retry.
Jian Li252750d2017-03-01 04:50:13 +0900115 * <p>
Jian Li92919592017-02-27 17:10:47 +0900116 * Emits mapping_update event if the state is changed
117 *
Jian Li252750d2017-03-01 04:50:13 +0900118 * @param type store type
Jian Li92919592017-02-27 17:10:47 +0900119 * @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 Li252750d2017-03-01 04:50:13 +0900127 * @param type store type
Jian Li92919592017-02-27 17:10:47 +0900128 * @param deviceId device identifier
129 */
Jian Li252750d2017-03-01 04:50:13 +0900130 default void purgeMappingEntry(Type type, DeviceId deviceId) {
131 }
Jian Li92919592017-02-27 17:10:47 +0900132
133 /**
134 * Removes all mapping entries from the specified store.
135 *
136 * @param type store type
137 */
138 void purgeMappingEntries(Type type);
Jian Li75642312017-01-19 14:23:05 -0800139}