Showing
5 changed files
with
123 additions
and
5 deletions
| ... | @@ -8,7 +8,6 @@ import org.onlab.packet.IpPrefix; | ... | @@ -8,7 +8,6 @@ import org.onlab.packet.IpPrefix; |
| 8 | import org.onlab.packet.MacAddress; | 8 | import org.onlab.packet.MacAddress; |
| 9 | import org.onlab.packet.VlanId; | 9 | import org.onlab.packet.VlanId; |
| 10 | 10 | ||
| 11 | -import java.util.Collections; | ||
| 12 | import java.util.HashMap; | 11 | import java.util.HashMap; |
| 13 | import java.util.Map; | 12 | import java.util.Map; |
| 14 | import java.util.Objects; | 13 | import java.util.Objects; |
| ... | @@ -27,7 +26,7 @@ public final class DefaultTrafficSelector implements TrafficSelector { | ... | @@ -27,7 +26,7 @@ public final class DefaultTrafficSelector implements TrafficSelector { |
| 27 | * @param criteria criteria | 26 | * @param criteria criteria |
| 28 | */ | 27 | */ |
| 29 | private DefaultTrafficSelector(Set<Criterion> criteria) { | 28 | private DefaultTrafficSelector(Set<Criterion> criteria) { |
| 30 | - this.criteria = Collections.unmodifiableSet(criteria); | 29 | + this.criteria = ImmutableSet.copyOf(criteria); |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | @Override | 32 | @Override | ... | ... |
| ... | @@ -7,7 +7,8 @@ import org.onlab.packet.IpPrefix; | ... | @@ -7,7 +7,8 @@ import org.onlab.packet.IpPrefix; |
| 7 | import org.onlab.packet.MacAddress; | 7 | import org.onlab.packet.MacAddress; |
| 8 | import org.onlab.packet.VlanId; | 8 | import org.onlab.packet.VlanId; |
| 9 | 9 | ||
| 10 | -import java.util.Collections; | 10 | +import com.google.common.collect.ImmutableList; |
| 11 | + | ||
| 11 | import java.util.LinkedList; | 12 | import java.util.LinkedList; |
| 12 | import java.util.List; | 13 | import java.util.List; |
| 13 | import java.util.Objects; | 14 | import java.util.Objects; |
| ... | @@ -25,7 +26,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -25,7 +26,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
| 25 | * @param instructions treatment instructions | 26 | * @param instructions treatment instructions |
| 26 | */ | 27 | */ |
| 27 | private DefaultTrafficTreatment(List<Instruction> instructions) { | 28 | private DefaultTrafficTreatment(List<Instruction> instructions) { |
| 28 | - this.instructions = Collections.unmodifiableList(instructions); | 29 | + this.instructions = ImmutableList.copyOf(instructions); |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | @Override | 32 | @Override | ... | ... |
core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java
0 → 100644
| 1 | +package org.onlab.onos.store.intent.impl; | ||
| 2 | + | ||
| 3 | +import static org.onlab.onos.net.intent.IntentState.FAILED; | ||
| 4 | +import static org.onlab.onos.net.intent.IntentState.INSTALLED; | ||
| 5 | +import static org.onlab.onos.net.intent.IntentState.SUBMITTED; | ||
| 6 | +import static org.onlab.onos.net.intent.IntentState.WITHDRAWN; | ||
| 7 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | +import java.util.Map; | ||
| 11 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 12 | + | ||
| 13 | +import org.apache.felix.scr.annotations.Activate; | ||
| 14 | +import org.apache.felix.scr.annotations.Component; | ||
| 15 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 16 | +import org.apache.felix.scr.annotations.Service; | ||
| 17 | +import org.onlab.onos.net.intent.InstallableIntent; | ||
| 18 | +import org.onlab.onos.net.intent.Intent; | ||
| 19 | +import org.onlab.onos.net.intent.IntentEvent; | ||
| 20 | +import org.onlab.onos.net.intent.IntentId; | ||
| 21 | +import org.onlab.onos.net.intent.IntentState; | ||
| 22 | +import org.onlab.onos.net.intent.IntentStore; | ||
| 23 | +import org.onlab.onos.net.intent.IntentStoreDelegate; | ||
| 24 | +import org.onlab.onos.store.AbstractStore; | ||
| 25 | +import org.slf4j.Logger; | ||
| 26 | + | ||
| 27 | +import com.google.common.collect.ImmutableSet; | ||
| 28 | + | ||
| 29 | +//FIXME: I LIE I AM NOT DISTRIBUTED | ||
| 30 | +@Component(immediate = true) | ||
| 31 | +@Service | ||
| 32 | +public class DistributedIntentStore | ||
| 33 | + extends AbstractStore<IntentEvent, IntentStoreDelegate> | ||
| 34 | + implements IntentStore { | ||
| 35 | + | ||
| 36 | + private final Logger log = getLogger(getClass()); | ||
| 37 | + private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); | ||
| 38 | + private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); | ||
| 39 | + private final Map<IntentId, List<InstallableIntent>> installable = | ||
| 40 | + new ConcurrentHashMap<>(); | ||
| 41 | + | ||
| 42 | + @Activate | ||
| 43 | + public void activate() { | ||
| 44 | + log.info("Started"); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Deactivate | ||
| 48 | + public void deactivate() { | ||
| 49 | + log.info("Stopped"); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public IntentEvent createIntent(Intent intent) { | ||
| 54 | + intents.put(intent.id(), intent); | ||
| 55 | + return this.setState(intent, IntentState.SUBMITTED); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public IntentEvent removeIntent(IntentId intentId) { | ||
| 60 | + Intent intent = intents.remove(intentId); | ||
| 61 | + installable.remove(intentId); | ||
| 62 | + IntentEvent event = this.setState(intent, WITHDRAWN); | ||
| 63 | + states.remove(intentId); | ||
| 64 | + return event; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public long getIntentCount() { | ||
| 69 | + return intents.size(); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public Iterable<Intent> getIntents() { | ||
| 74 | + return ImmutableSet.copyOf(intents.values()); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public Intent getIntent(IntentId intentId) { | ||
| 79 | + return intents.get(intentId); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public IntentState getIntentState(IntentId id) { | ||
| 84 | + return states.get(id); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + public IntentEvent setState(Intent intent, IntentState state) { | ||
| 89 | + IntentId id = intent.id(); | ||
| 90 | + states.put(id, state); | ||
| 91 | + IntentEvent.Type type = (state == SUBMITTED ? IntentEvent.Type.SUBMITTED : | ||
| 92 | + (state == INSTALLED ? IntentEvent.Type.INSTALLED : | ||
| 93 | + (state == FAILED ? IntentEvent.Type.FAILED : | ||
| 94 | + state == WITHDRAWN ? IntentEvent.Type.WITHDRAWN : | ||
| 95 | + null))); | ||
| 96 | + return type == null ? null : new IntentEvent(type, intent); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @Override | ||
| 100 | + public void addInstallableIntents(IntentId intentId, List<InstallableIntent> result) { | ||
| 101 | + installable.put(intentId, result); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + @Override | ||
| 105 | + public List<InstallableIntent> getInstallableIntents(IntentId intentId) { | ||
| 106 | + return installable.get(intentId); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + @Override | ||
| 110 | + public void removeInstalledIntents(IntentId intentId) { | ||
| 111 | + installable.remove(intentId); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | +} |
| ... | @@ -26,6 +26,7 @@ import org.onlab.onos.net.PortNumber; | ... | @@ -26,6 +26,7 @@ import org.onlab.onos.net.PortNumber; |
| 26 | import org.onlab.onos.net.device.DefaultDeviceDescription; | 26 | import org.onlab.onos.net.device.DefaultDeviceDescription; |
| 27 | import org.onlab.onos.net.device.DefaultPortDescription; | 27 | import org.onlab.onos.net.device.DefaultPortDescription; |
| 28 | import org.onlab.onos.net.flow.DefaultFlowRule; | 28 | import org.onlab.onos.net.flow.DefaultFlowRule; |
| 29 | +import org.onlab.onos.net.flow.DefaultTrafficSelector; | ||
| 29 | import org.onlab.onos.net.flow.FlowId; | 30 | import org.onlab.onos.net.flow.FlowId; |
| 30 | import org.onlab.onos.net.host.DefaultHostDescription; | 31 | import org.onlab.onos.net.host.DefaultHostDescription; |
| 31 | import org.onlab.onos.net.host.HostDescription; | 32 | import org.onlab.onos.net.host.HostDescription; |
| ... | @@ -88,7 +89,8 @@ public final class KryoNamespaces { | ... | @@ -88,7 +89,8 @@ public final class KryoNamespaces { |
| 88 | HostDescription.class, | 89 | HostDescription.class, |
| 89 | DefaultHostDescription.class, | 90 | DefaultHostDescription.class, |
| 90 | DefaultFlowRule.class, | 91 | DefaultFlowRule.class, |
| 91 | - FlowId.class | 92 | + FlowId.class, |
| 93 | + DefaultTrafficSelector.class | ||
| 92 | ) | 94 | ) |
| 93 | .register(URI.class, new URISerializer()) | 95 | .register(URI.class, new URISerializer()) |
| 94 | .register(NodeId.class, new NodeIdSerializer()) | 96 | .register(NodeId.class, new NodeIdSerializer()) | ... | ... |
| ... | @@ -171,6 +171,7 @@ public final class KryoNamespace implements KryoFactory { | ... | @@ -171,6 +171,7 @@ public final class KryoNamespace implements KryoFactory { |
| 171 | Kryo kryo = getKryo(); | 171 | Kryo kryo = getKryo(); |
| 172 | try { | 172 | try { |
| 173 | kryo.writeClassAndObject(out, obj); | 173 | kryo.writeClassAndObject(out, obj); |
| 174 | + out.flush(); | ||
| 174 | return out.toBytes(); | 175 | return out.toBytes(); |
| 175 | } finally { | 176 | } finally { |
| 176 | putKryo(kryo); | 177 | putKryo(kryo); |
| ... | @@ -188,6 +189,7 @@ public final class KryoNamespace implements KryoFactory { | ... | @@ -188,6 +189,7 @@ public final class KryoNamespace implements KryoFactory { |
| 188 | Kryo kryo = getKryo(); | 189 | Kryo kryo = getKryo(); |
| 189 | try { | 190 | try { |
| 190 | kryo.writeClassAndObject(out, obj); | 191 | kryo.writeClassAndObject(out, obj); |
| 192 | + out.flush(); | ||
| 191 | } finally { | 193 | } finally { |
| 192 | putKryo(kryo); | 194 | putKryo(kryo); |
| 193 | } | 195 | } | ... | ... |
-
Please register or login to post a comment