Jonathan Hart

Initial implementation of GossipIntentStore.

Create/update operations are implemented and working in 2-node cluster.
No remove operations yet.

Change-Id: Ief68c9d5c3bb483823b6f92d29fa83df0ab7b58f
1 +/*
2 + * Copyright 2015 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.net.intent;
17 +
18 +import org.onosproject.store.Timestamp;
19 +
20 +/**
21 + * Logical clock service that issues per-intent timestamps.
22 + */
23 +public interface IntentClockService {
24 +
25 + /**
26 + * Returns a new timestamp for the specified intent.
27 + *
28 + * @param intentId identifier for the intent.
29 + * @return timestamp
30 + */
31 + public Timestamp getTimestamp(IntentId intentId);
32 +}
1 +/*
2 + * Copyright 2015 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.store.intent.impl;
17 +
18 +import org.onosproject.store.cluster.messaging.MessageSubject;
19 +
20 +/**
21 + * Message subjects for internal gossip intent store node-to-node messages.
22 + */
23 +public final class GossipIntentStoreMessageSubjects {
24 + private GossipIntentStoreMessageSubjects() {}
25 +
26 + public static final MessageSubject INTENT_UPDATED_MSG
27 + = new MessageSubject("peer-intent-updated");
28 + public static final MessageSubject INTENT_SET_INSTALLABLES_MSG
29 + = new MessageSubject("peer-intent-set-installables");
30 + public static final MessageSubject INTENT_ANTI_ENTROPY_ADVERTISEMENT
31 + = new MessageSubject("intent-anti-entropy-advertisement");
32 +}
1 +/*
2 + * Copyright 2015 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.store.intent.impl;
17 +
18 +import org.apache.felix.scr.annotations.Activate;
19 +import org.apache.felix.scr.annotations.Component;
20 +import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Service;
22 +import org.onosproject.net.intent.IntentClockService;
23 +import org.onosproject.net.intent.IntentId;
24 +import org.onosproject.store.Timestamp;
25 +import org.onosproject.store.impl.WallClockTimestamp;
26 +import org.slf4j.Logger;
27 +
28 +import static org.slf4j.LoggerFactory.getLogger;
29 +
30 +/**
31 + * IntentClockService that issues timestamps based on local wallclock time.
32 + */
33 +@Component(immediate = true)
34 +@Service
35 +public class IntentClockManager implements IntentClockService {
36 +
37 + private final Logger log = getLogger(getClass());
38 +
39 + @Activate
40 + public void activate() {
41 + log.info("Started");
42 + }
43 +
44 + @Deactivate
45 + public void deactivate() {
46 + log.info("Stopped");
47 + }
48 +
49 + @Override
50 + public Timestamp getTimestamp(IntentId intentId) {
51 + return new WallClockTimestamp();
52 + }
53 +}
1 +/*
2 + * Copyright 2015 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.store.intent.impl;
17 +
18 +import org.onosproject.net.intent.Intent;
19 +import org.onosproject.net.intent.IntentId;
20 +import org.onosproject.net.intent.IntentState;
21 +import org.onosproject.store.Timestamp;
22 +
23 +/**
24 + * Information published by GossipIntentStore to notify peers of an intent
25 + * creation or state update event.
26 + */
27 +public class InternalIntentEvent {
28 +
29 + private final IntentId intentId;
30 + private final Intent intent;
31 + private final IntentState state;
32 + private final Timestamp timestamp;
33 +
34 + public InternalIntentEvent(IntentId intentId, Intent intent, IntentState state,
35 + Timestamp timestamp) {
36 + this.intentId = intentId;
37 + this.intent = intent;
38 + this.state = state;
39 + this.timestamp = timestamp;
40 + }
41 +
42 + public IntentId intentId() {
43 + return intentId;
44 + }
45 +
46 + public Intent intent() {
47 + return intent;
48 + }
49 +
50 + public IntentState state() {
51 + return state;
52 + }
53 +
54 + public Timestamp timestamp() {
55 + return timestamp;
56 + }
57 +
58 + // Needed for serialization.
59 + @SuppressWarnings("unused")
60 + private InternalIntentEvent() {
61 + intentId = null;
62 + intent = null;
63 + state = null;
64 + timestamp = null;
65 + }
66 +}
1 +/*
2 + * Copyright 2015 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.store.intent.impl;
17 +
18 +import org.onosproject.net.intent.Intent;
19 +import org.onosproject.net.intent.IntentId;
20 +import org.onosproject.store.Timestamp;
21 +
22 +import java.util.List;
23 +
24 +/**
25 + * Information published by GossipIntentStore to notify peers of an intent
26 + * set installables event.
27 + */
28 +public class InternalSetInstallablesEvent {
29 +
30 + private final IntentId intentId;
31 + private final List<Intent> installables;
32 + private final Timestamp timestamp;
33 +
34 + public InternalSetInstallablesEvent(IntentId intentId,
35 + List<Intent> installables,
36 + Timestamp timestamp) {
37 + this.intentId = intentId;
38 + this.installables = installables;
39 + this.timestamp = timestamp;
40 + }
41 +
42 + public IntentId intentId() {
43 + return intentId;
44 + }
45 +
46 + public List<Intent> installables() {
47 + return installables;
48 + }
49 +
50 + public Timestamp timestamp() {
51 + return timestamp;
52 + }
53 +
54 + // Needed for serialization.
55 + @SuppressWarnings("unused")
56 + private InternalSetInstallablesEvent() {
57 + intentId = null;
58 + installables = null;
59 + timestamp = null;
60 + }
61 +}