blob: a8bea2ea42274d567f91124c7778fd70a335243a [file] [log] [blame]
Brian O'Connor66630c82014-10-02 21:08:19 -07001package org.onlab.onos.net.intent.impl;
2
3import java.util.Arrays;
4import java.util.List;
5import java.util.Set;
6
7import org.apache.felix.scr.annotations.Activate;
8import org.apache.felix.scr.annotations.Component;
9import org.apache.felix.scr.annotations.Deactivate;
10import org.apache.felix.scr.annotations.Reference;
11import org.apache.felix.scr.annotations.ReferenceCardinality;
12import org.onlab.onos.net.ConnectPoint;
13import org.onlab.onos.net.Path;
14import org.onlab.onos.net.PortNumber;
15import org.onlab.onos.net.intent.HostToHostIntent;
16import org.onlab.onos.net.intent.IdGenerator;
17import org.onlab.onos.net.intent.Intent;
18import org.onlab.onos.net.intent.IntentCompiler;
19import org.onlab.onos.net.intent.IntentExtensionService;
20import org.onlab.onos.net.intent.IntentId;
21import org.onlab.onos.net.intent.PathIntent;
22import org.onlab.onos.net.topology.PathService;
23
24/**
25 * A intent compiler for {@link HostToHostIntent}.
26 */
27@Component(immediate = true)
28public class HostToHostIntentCompiler
29 implements IntentCompiler<HostToHostIntent> {
30
31 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
32 protected IntentExtensionService intentManager;
33
34 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
35 protected PathService pathService;
36
37 private IdGenerator<IntentId> intentIdGenerator;
38
39 @Activate
40 public void activate() {
41 IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
42 intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
43 intentManager.registerCompiler(HostToHostIntent.class, this);
44 }
45
46 @Deactivate
47 public void deactivate() {
48 intentManager.unregisterCompiler(HostToHostIntent.class);
49 }
50
51 @Override
52 public List<Intent> compile(HostToHostIntent intent) {
53 Set<Path> paths = pathService.getPaths(intent.getSrc(), intent.getDst());
54 if (paths.isEmpty()) {
55 throw new PathNotFoundException();
56 }
57 Path path = paths.iterator().next();
58
59 return Arrays.asList((Intent) new PathIntent(
60 intentIdGenerator.getNewId(),
61 intent.getTrafficSelector(),
62 intent.getTrafficTreatment(),
63 new ConnectPoint(intent.getSrc(), PortNumber.ALL),
64 new ConnectPoint(intent.getDst(), PortNumber.ALL),
65 path));
66 }
67}