blob: 4d989ac251c1b42842db83882a4f37f1cd133a51 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Brian O'Connor66630c82014-10-02 21:08:19 -070016package org.onlab.onos.net.intent.impl;
17
Brian O'Connor66630c82014-10-02 21:08:19 -070018import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
tomf5c9d922014-10-03 15:22:03 -070023import org.onlab.onos.net.Host;
Brian O'Connor66630c82014-10-02 21:08:19 -070024import org.onlab.onos.net.Path;
tomf5c9d922014-10-03 15:22:03 -070025import org.onlab.onos.net.flow.TrafficSelector;
26import org.onlab.onos.net.host.HostService;
Brian O'Connor66630c82014-10-02 21:08:19 -070027import org.onlab.onos.net.intent.HostToHostIntent;
Brian O'Connor66630c82014-10-02 21:08:19 -070028import org.onlab.onos.net.intent.Intent;
Brian O'Connor66630c82014-10-02 21:08:19 -070029import org.onlab.onos.net.intent.PathIntent;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080030
31import java.util.Arrays;
32import java.util.List;
Brian O'Connor66630c82014-10-02 21:08:19 -070033
tomf5c9d922014-10-03 15:22:03 -070034import static org.onlab.onos.net.flow.DefaultTrafficSelector.builder;
35
Brian O'Connor66630c82014-10-02 21:08:19 -070036/**
37 * A intent compiler for {@link HostToHostIntent}.
38 */
39@Component(immediate = true)
40public class HostToHostIntentCompiler
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080041 extends ConnectivityIntentCompiler<HostToHostIntent> {
Brian O'Connor66630c82014-10-02 21:08:19 -070042
tomf5c9d922014-10-03 15:22:03 -070043 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected HostService hostService;
45
Brian O'Connor66630c82014-10-02 21:08:19 -070046 @Activate
47 public void activate() {
Brian O'Connor66630c82014-10-02 21:08:19 -070048 intentManager.registerCompiler(HostToHostIntent.class, this);
49 }
50
51 @Deactivate
52 public void deactivate() {
53 intentManager.unregisterCompiler(HostToHostIntent.class);
54 }
55
56 @Override
57 public List<Intent> compile(HostToHostIntent intent) {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080058 Path pathOne = getPath(intent, intent.one(), intent.two());
59 Path pathTwo = getPath(intent, intent.two(), intent.one());
Brian O'Connor66630c82014-10-02 21:08:19 -070060
tomf5c9d922014-10-03 15:22:03 -070061 Host one = hostService.getHost(intent.one());
62 Host two = hostService.getHost(intent.two());
63
64 return Arrays.asList(createPathIntent(pathOne, one, two, intent),
65 createPathIntent(pathTwo, two, one, intent));
66 }
67
68 // Creates a path intent from the specified path and original connectivity intent.
69 private Intent createPathIntent(Path path, Host src, Host dst,
70 HostToHostIntent intent) {
tom85258ee2014-10-07 00:10:02 -070071 TrafficSelector selector = builder(intent.selector())
tomf5c9d922014-10-03 15:22:03 -070072 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
Ray Milkey460f4022014-11-05 15:41:43 -080073 return new PathIntent(intent.appId(), selector, intent.treatment(),
74 path, intent.constraints());
tomf5c9d922014-10-03 15:22:03 -070075 }
76
Brian O'Connor66630c82014-10-02 21:08:19 -070077}