Xin Jin
Committed by Brian O'Connor

Adding experimental Flow Objective composition

Change-Id: I35e4414845ad5034145157ab83f933e40f75a1d9
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.flowobjective.FlowObjectiveService;
/**
* Manages FlowObjectiveComposition policy.
*/
@Command(scope = "onos", name = "policy",
description = "Manages FlowObjectiveComposition policy")
public class FlowObjectiveCompositionCommand extends AbstractShellCommand {
@Argument(index = 0, name = "command",
description = "Command name (install)",
required = true, multiValued = false)
String command = null;
@Argument(index = 1, name = "names", description = "policy string",
required = true, multiValued = true)
String[] policies = null;
@Override
protected void execute() {
FlowObjectiveService service = get(FlowObjectiveService.class);
service.initPolicy(policies[0]);
print("Policy %s installed", policies[0]);
}
}
......@@ -30,6 +30,10 @@
</command>
<command>
<action class="org.onosproject.cli.net.FlowObjectiveCompositionCommand"/>
</command>
<command>
<action class="org.onosproject.cli.app.ApplicationsListCommand"/>
</command>
......
......@@ -56,4 +56,10 @@ public interface FlowObjectiveService {
*/
int allocateNextId();
/**
* Installs the filtering rules onto the specified device.
*
* @param policy policy expression
*/
void initPolicy(String policy);
}
......
......@@ -218,6 +218,9 @@ public class FlowObjectiveManager implements FlowObjectiveService {
return flowObjectiveStore.allocateNextId();
}
@Override
public void initPolicy(String policy) {}
private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) {
if (fwd.nextId() != null &&
flowObjectiveStore.getNextGroup(fwd.nextId()) == null) {
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.flowobjective.impl.composition;
import org.onosproject.net.flowobjective.FilteringObjective;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Provides a table to store Fitler.
*/
public class FilterTable {
protected Map<Integer, FilteringObjective> filterMap;
public FilterTable() {
this.filterMap = new HashMap<>();
}
public List<FilteringObjective> updateFilter(FilteringObjective filteringObjective) {
List<FilteringObjective> updates = new ArrayList<>();
switch (filteringObjective.op()) {
case ADD:
this.filterMap.put(filteringObjective.id(), filteringObjective);
updates.add(filteringObjective);
break;
case REMOVE:
this.filterMap.remove(filteringObjective.id());
updates.add(filteringObjective);
break;
default:
break;
}
return updates;
}
public List<FilteringObjective> updateFilter(List<FilteringObjective> filteringObjectives) {
List<FilteringObjective> updates = new ArrayList<>();
for (FilteringObjective filteringObjective : filteringObjectives) {
updates.addAll(this.updateFilter(filteringObjective));
}
return updates;
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.flowobjective.impl.composition;
import org.onosproject.net.flowobjective.DefaultForwardingObjective;
import org.onosproject.net.flowobjective.ForwardingObjective;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Provides a table to store Forward.
*/
public class ForwardTable {
protected Map<Integer, ForwardingObjective> forwardMap;
protected Map<Integer, List<ForwardingObjective>> generatedParentForwardingObjectiveMap;
public ForwardTable() {
this.forwardMap = new HashMap<>();
this.generatedParentForwardingObjectiveMap = new HashMap<>();
}
public ForwardUpdateTable updateForward(ForwardingObjective forwardingObjective) {
ForwardUpdateTable updates = new ForwardUpdateTable();
switch (forwardingObjective.op()) {
case ADD:
this.forwardMap.put(forwardingObjectiveHash(forwardingObjective), forwardingObjective);
this.generatedParentForwardingObjectiveMap
.put(forwardingObjectiveHash(forwardingObjective), new ArrayList<>());
updates.addObjectives.add(forwardingObjective);
break;
case REMOVE:
if (this.forwardMap.remove(forwardingObjectiveHash(forwardingObjective)) != null) {
updates.removeObjectives.add(forwardingObjective);
}
break;
default:
break;
}
return updates;
}
public ForwardUpdateTable updateForward(List<ForwardingObjective> forwardingObjectives) {
ForwardUpdateTable updates = new ForwardUpdateTable();
for (ForwardingObjective forwardingObjective : forwardingObjectives) {
updates.addUpdateTable(this.updateForward(forwardingObjective));
}
return updates;
}
public void addGeneratedParentForwardingObjective(ForwardingObjective child, ForwardingObjective parent) {
this.generatedParentForwardingObjectiveMap.get(forwardingObjectiveHash(child)).add(parent);
}
public void deleteGeneratedParentForwardingObjective(List<ForwardingObjective> children) {
for (ForwardingObjective fo : children) {
this.generatedParentForwardingObjectiveMap.remove(forwardingObjectiveHash(fo));
}
}
private List<ForwardingObjective> getGeneratedParentForwardingObjective(ForwardingObjective child) {
return this.generatedParentForwardingObjectiveMap.get(forwardingObjectiveHash(child));
}
public List<ForwardingObjective> getGeneratedParentForwardingObjectiveForRemove(ForwardingObjective child) {
List<ForwardingObjective> fos = this.generatedParentForwardingObjectiveMap.get(forwardingObjectiveHash(child));
List<ForwardingObjective> removeFos = new ArrayList<>();
for (ForwardingObjective fo : fos) {
removeFos.add(DefaultForwardingObjective.builder()
.fromApp(fo.appId())
.makePermanent()
.withFlag(fo.flag())
.withPriority(fo.priority())
.withSelector(fo.selector())
.withTreatment(fo.treatment())
.remove());
}
return removeFos;
}
public Collection<ForwardingObjective> getForwardingObjectives() {
return this.forwardMap.values();
}
public static int forwardingObjectiveHash(ForwardingObjective forwardingObjective) {
return Objects.hash(forwardingObjective.selector(), forwardingObjective.flag(),
forwardingObjective.permanent(), forwardingObjective.timeout(),
forwardingObjective.appId(), forwardingObjective.priority(),
forwardingObjective.nextId(), forwardingObjective.treatment());
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.flowobjective.impl.composition;
import org.onosproject.net.flowobjective.ForwardingObjective;
import java.util.ArrayList;
import java.util.List;
/**
* Provides an update table for Forward.
*/
public class ForwardUpdateTable {
public List<ForwardingObjective> addObjectives;
public List<ForwardingObjective> removeObjectives;
public ForwardUpdateTable() {
this.addObjectives = new ArrayList<>();
this.removeObjectives = new ArrayList<>();
}
public void addUpdateTable(ForwardUpdateTable updateTable) {
this.addObjectives.addAll(updateTable.addObjectives);
this.removeObjectives.addAll(updateTable.removeObjectives);
}
public List<ForwardingObjective> toForwardingObjectiveList() {
List<ForwardingObjective> forwardingObjectives = new ArrayList<>();
forwardingObjectives.addAll(this.addObjectives);
forwardingObjectives.addAll(this.removeObjectives);
return forwardingObjectives;
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.flowobjective.impl.composition;
import org.onosproject.net.flowobjective.NextObjective;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Provides a table to store Next.
*/
public class NextTable {
protected Map<Integer, NextObjective> nextMap;
public NextTable() {
this.nextMap = new HashMap<>();
}
public List<NextObjective> updateNext(NextObjective nextObjective) {
List<NextObjective> updates = new ArrayList<>();
switch (nextObjective.op()) {
case ADD:
this.nextMap.put(nextObjective.id(), nextObjective);
updates.add(nextObjective);
break;
case REMOVE:
this.nextMap.remove(nextObjective.id());
updates.add(nextObjective);
break;
default:
break;
}
return updates;
}
public List<NextObjective> updateNext(List<NextObjective> nextObjectives) {
List<NextObjective> updates = new ArrayList<>();
for (NextObjective nextObjective : nextObjectives) {
updates.addAll(this.updateNext(nextObjective));
}
return updates;
}
}