Jonathan Hart
Committed by Gerrit Code Review

Adapt FIBs to new route interface

Change-Id: I8ac19ad578aac4607fd8319186b6568a21edc1fd
......@@ -89,9 +89,9 @@ public class IntentSynchronizer implements IntentSynchronizationService,
@Activate
public void activate() {
intentsSynchronizerExecutor = createExecutor();
this.localNodeId = clusterService.getLocalNode().id();
this.appId = coreService.registerApplication(APP_NAME);
intentsSynchronizerExecutor = createExecutor();
leadershipService.addListener(leadershipEventListener);
leadershipService.runForLeadership(appId.name());
......
......@@ -17,9 +17,7 @@
package org.onosproject.routing.impl;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
......@@ -40,6 +38,10 @@ import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceEvent;
import org.onosproject.incubator.net.intf.InterfaceListener;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.incubator.net.routing.ResolvedRoute;
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.config.NetworkConfigEvent;
......@@ -56,24 +58,19 @@ import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flowobjective.DefaultFilteringObjective;
import org.onosproject.net.flowobjective.DefaultForwardingObjective;
import org.onosproject.net.flowobjective.DefaultNextObjective;
import org.onosproject.net.flowobjective.DefaultObjectiveContext;
import org.onosproject.net.flowobjective.FilteringObjective;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.NextObjective;
import org.onosproject.net.flowobjective.ObjectiveContext;
import org.onosproject.net.flowobjective.DefaultObjectiveContext;
import org.onosproject.routing.FibEntry;
import org.onosproject.routing.FibListener;
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.config.RouterConfig;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -96,7 +93,7 @@ public class SingleSwitchFibInstaller {
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RoutingService routingService;
protected RouteService routeService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected InterfaceService interfaceService;
......@@ -137,11 +134,9 @@ public class SingleSwitchFibInstaller {
// Mapping from next hop IP to next hop object containing group info
private final Map<IpAddress, Integer> nextHops = Maps.newHashMap();
// Stores FIB updates that are waiting for groups to be set up
private final Multimap<NextHopGroupKey, FibEntry> pendingUpdates = HashMultimap.create();
//interface object for event
private InternalInterfaceListener internalInterfaceList = new InternalInterfaceListener();
private InternalRouteListener routeListener = new InternalRouteListener();
@Activate
protected void activate(ComponentContext context) {
......@@ -155,9 +150,6 @@ public class SingleSwitchFibInstaller {
interfaceService.addListener(internalInterfaceList);
routingService.addFibListener(new InternalFibListener());
routingService.start();
updateConfig();
log.info("Started");
......@@ -165,10 +157,8 @@ public class SingleSwitchFibInstaller {
@Deactivate
protected void deactivate() {
routingService.stop();
routeService.removeListener(routeListener);
deviceService.removeListener(deviceListener);
interfaceService.removeListener(internalInterfaceList);
//processIntfFilters(false, configService.getInterfaces()); //TODO necessary?
......@@ -208,6 +198,8 @@ public class SingleSwitchFibInstaller {
interfaces = routerConfig.getInterfaces();
log.info("Using interfaces: {}", interfaces.isEmpty() ? "all" : interfaces);
routeService.addListener(routeListener);
updateDevice();
}
......@@ -229,55 +221,30 @@ public class SingleSwitchFibInstaller {
}
}
private void updateFibEntry(Collection<FibUpdate> updates) {
Map<FibEntry, Integer> toInstall = new HashMap<>(updates.size());
for (FibUpdate update : updates) {
FibEntry entry = update.entry();
addNextHop(entry);
private void updateRoute(ResolvedRoute route) {
addNextHop(route);
Integer nextId;
synchronized (pendingUpdates) {
nextId = nextHops.get(entry.nextHopIp());
}
toInstall.put(update.entry(), nextId);
synchronized (this) {
nextId = nextHops.get(route.nextHop());
}
installFlows(toInstall);
}
private void installFlows(Map<FibEntry, Integer> entriesToInstall) {
for (Map.Entry<FibEntry, Integer> entry : entriesToInstall.entrySet()) {
FibEntry fibEntry = entry.getKey();
Integer nextId = entry.getValue();
flowObjectiveService.forward(deviceId,
generateRibForwardingObj(fibEntry.prefix(), nextId).add());
log.trace("Sending forwarding objective {} -> nextId:{}", fibEntry, nextId);
}
generateRibForwardingObj(route.prefix(), nextId).add());
log.trace("Sending forwarding objective {} -> nextId:{}", route, nextId);
}
private synchronized void deleteFibEntry(Collection<FibUpdate> withdraws) {
for (FibUpdate update : withdraws) {
FibEntry entry = update.entry();
//Integer nextId = nextHops.get(entry.nextHopIp());
private synchronized void deleteRoute(ResolvedRoute route) {
//Integer nextId = nextHops.get(route.nextHop());
/* Group group = deleteNextHop(entry.prefix());
/* Group group = deleteNextHop(route.prefix());
if (group == null) {
log.warn("Group not found when deleting {}", entry);
log.warn("Group not found when deleting {}", route);
return;
}*/
flowObjectiveService.forward(deviceId,
generateRibForwardingObj(entry.prefix(), null).remove());
}
generateRibForwardingObj(route.prefix(), null).remove());
}
private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix,
......@@ -306,20 +273,20 @@ public class SingleSwitchFibInstaller {
return fwdBuilder;
}
private synchronized void addNextHop(FibEntry entry) {
prefixToNextHop.put(entry.prefix(), entry.nextHopIp());
if (nextHopsCount.count(entry.nextHopIp()) == 0) {
private synchronized void addNextHop(ResolvedRoute route) {
prefixToNextHop.put(route.prefix(), route.nextHop());
if (nextHopsCount.count(route.nextHop()) == 0) {
// There was no next hop in the multiset
Interface egressIntf = interfaceService.getMatchingInterface(entry.nextHopIp());
Interface egressIntf = interfaceService.getMatchingInterface(route.nextHop());
if (egressIntf == null) {
log.warn("no egress interface found for {}", entry);
log.warn("no egress interface found for {}", route);
return;
}
NextHopGroupKey groupKey = new NextHopGroupKey(entry.nextHopIp());
NextHopGroupKey groupKey = new NextHopGroupKey(route.nextHop());
NextHop nextHop = new NextHop(entry.nextHopIp(), entry.nextHopMac(), groupKey);
NextHop nextHop = new NextHop(route.nextHop(), route.nextHopMac(), groupKey);
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
.setEthSrc(egressIntf.mac())
......@@ -356,12 +323,12 @@ public class SingleSwitchFibInstaller {
if (routeToNextHop) {
// Install route to next hop
ForwardingObjective fob =
generateRibForwardingObj(IpPrefix.valueOf(entry.nextHopIp(), 32), nextId).add();
generateRibForwardingObj(IpPrefix.valueOf(route.nextHop(), 32), nextId).add();
flowObjectiveService.forward(deviceId, fob);
}
}
nextHopsCount.add(entry.nextHopIp());
nextHopsCount.add(route.nextHop());
}
/*private synchronized Group deleteNextHop(IpPrefix prefix) {
......@@ -452,13 +419,21 @@ public class SingleSwitchFibInstaller {
flowObjectiveService.filter(deviceId, filter);
}
private class InternalFibListener implements FibListener {
private class InternalRouteListener implements RouteListener {
@Override
public void update(Collection<FibUpdate> updates,
Collection<FibUpdate> withdraws) {
SingleSwitchFibInstaller.this.deleteFibEntry(withdraws);
SingleSwitchFibInstaller.this.updateFibEntry(updates);
public void event(RouteEvent event) {
ResolvedRoute route = event.subject();
switch (event.type()) {
case ROUTE_ADDED:
case ROUTE_UPDATED:
updateRoute(route);
break;
case ROUTE_REMOVED:
deleteRoute(route);
break;
default:
break;
}
}
}
......
......@@ -15,13 +15,11 @@
*/
package org.onosproject.routing.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ethernet;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
......@@ -31,11 +29,14 @@ import org.onosproject.TestApplicationId;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.CoreServiceAdapter;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceListener;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
import org.onosproject.incubator.net.routing.ResolvedRoute;
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteServiceAdapter;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
......@@ -53,25 +54,22 @@ import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.NextObjective;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.routing.FibEntry;
import org.onosproject.routing.FibListener;
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.RoutingServiceAdapter;
import org.onosproject.routing.config.RouterConfig;
import org.osgi.service.component.ComponentContext;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.anyString;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.easymock.EasyMock.verify;
......@@ -79,76 +77,68 @@ import static org.easymock.EasyMock.verify;
/**
* Unit tests for SingleSwitchFibInstaller.
*/
public class SingleSwitchFibInstallerTest extends AbstractIntentTest {
public class SingleSwitchFibInstallerTest {
private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001");
//for interface service setup
private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000001"),
PortNumber.portNumber(1));
DEVICE_ID, PortNumber.portNumber(1));
private static final ConnectPoint SW1_ETH2 = new ConnectPoint(
DEVICE_ID, PortNumber.portNumber(2));
private static final int NEXT_ID = 11;
private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000002"),
PortNumber.portNumber(1));
private static final VlanId VLAN1 = VlanId.vlanId((short) 1);
private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000003"),
PortNumber.portNumber(1));
private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
private static final IpAddress NEXT_HOP1 = IpAddress.valueOf("192.168.10.1");
private static final IpAddress NEXT_HOP2 = IpAddress.valueOf("192.168.20.1");
private static final InterfaceIpAddress INTF1 =
InterfaceIpAddress.valueOf("192.168.10.2/24");
private static final InterfaceIpAddress INTF2 =
InterfaceIpAddress.valueOf("192.168.20.2/24");
private static final ConnectPoint SW4_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000004"),
PortNumber.portNumber(1));
private DeviceId deviceId = DeviceId.deviceId("of:0000000000000001");
private final Set<Interface> interfaces = Sets.newHashSet();
private InterfaceService interfaceService;
private NetworkConfigService networkConfigService;
private FlowObjectiveService flowObjectiveService;
private DeviceService deviceService;
private static final ApplicationId APPID = TestApplicationId.create("update fib");
private FibListener fibListener;
private static final ApplicationId APPID = TestApplicationId.create("foo");
private RouteListener routeListener;
private DeviceListener deviceListener;
private CoreService coreService;
private RouterConfig routerConfig;
private RoutingService routingService;
private SingleSwitchFibInstaller sSfibInstaller;
private InterfaceListener interfaceListener;
@Before
public void setUp() throws Exception {
super.setUp();
sSfibInstaller = new SingleSwitchFibInstaller();
//component config service
ComponentConfigService mockComponenetConfigServ = EasyMock.createMock(ComponentConfigService.class);
expect(mockComponenetConfigServ.getProperties(anyObject())).andReturn(ImmutableSet.of());
mockComponenetConfigServ.registerProperties(sSfibInstaller.getClass());
EasyMock.expectLastCall();
mockComponenetConfigServ.unregisterProperties(sSfibInstaller.getClass(), false);
EasyMock.expectLastCall();
expect(mockComponenetConfigServ.getProperties(anyObject())).andReturn(ImmutableSet.of());
sSfibInstaller.componentConfigService = mockComponenetConfigServ;
replay(mockComponenetConfigServ);
//component context
ComponentContext mockContext = EasyMock.createMock(ComponentContext.class);
Dictionary properties = null;
expect(mockContext.getProperties()).andReturn(properties);
replay(mockContext);
coreService = new TestCoreService();
routingService = new TestRoutingService();
sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
ComponentContext mockContext = createNiceMock(ComponentContext.class);
routerConfig = new TestRouterConfig();
//interfaceService = createMock(InterfaceService.class);
interfaceService = new TestInterfaceService();
interfaceService = createMock(InterfaceService.class);
networkConfigService = createMock(NetworkConfigService.class);
flowObjectiveService = createMock(FlowObjectiveService.class);
deviceService = new TestDeviceService();
CoreService coreService = createNiceMock(CoreService.class);
expect(coreService.registerApplication(anyString())).andReturn(APPID);
replay(coreService);
sSfibInstaller.networkConfigService = networkConfigService;
sSfibInstaller.interfaceService = interfaceService;
sSfibInstaller.flowObjectiveService = flowObjectiveService;
sSfibInstaller.coreService = coreService;
sSfibInstaller.routingService = new TestRoutingService();
sSfibInstaller.routeService = new TestRouteService();
sSfibInstaller.deviceService = deviceService;
setUpNetworkConfigService();
......@@ -160,48 +150,32 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest {
* Sets up InterfaceService.
*/
private void setUpInterfaceService() {
Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
interfaceIpAddresses1.add(new InterfaceIpAddress(
IpAddress.valueOf("192.168.10.1"),
IpPrefix.valueOf("192.168.10.0/24")));
Interface sw1Eth1 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH1,
interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
VlanId.NONE);
interfaceService.addListener(anyObject(InterfaceListener.class));
expectLastCall().andDelegateTo(new TestInterfaceService());
// Interface with no VLAN
Interface sw1Eth1 = new Interface("intf1", SW1_ETH1,
Collections.singletonList(INTF1), MAC1, VlanId.NONE);
expect(interfaceService.getMatchingInterface(NEXT_HOP1)).andReturn(sw1Eth1);
interfaces.add(sw1Eth1);
Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet();
interfaceIpAddresses2.add(new InterfaceIpAddress(IpAddress.valueOf("192.168.20.1"),
IpPrefix.valueOf("192.168.20.0/24")));
Interface sw2Eth1 = new Interface(SW2_ETH1.deviceId().toString(), SW2_ETH1,
interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
VlanId.NONE);
// Interface with a VLAN
Interface sw2Eth1 = new Interface("intf2", SW1_ETH2,
Collections.singletonList(INTF2), MAC2, VLAN1);
expect(interfaceService.getMatchingInterface(NEXT_HOP2)).andReturn(sw2Eth1);
interfaces.add(sw2Eth1);
Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet();
interfaceIpAddresses3.add(
new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
IpPrefix.valueOf("192.168.30.0/24")));
Interface sw3Eth1 = new Interface(SW3_ETH1.deviceId().toString(), SW3_ETH1,
interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE);
interfaces.add(sw3Eth1);
InterfaceIpAddress interfaceIpAddress4 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.40.1"),
IpPrefix.valueOf("192.168.40.0/24"));
Interface sw4Eth1 = new Interface(SW4_ETH1.deviceId().toString(), SW4_ETH1,
Sets.newHashSet(interfaceIpAddress4),
MacAddress.valueOf("00:00:00:00:00:04"),
VlanId.vlanId((short) 1));
interfaces.add(sw4Eth1);
expect(interfaceService.getInterfaces()).andReturn(interfaces);
replay(interfaceService);
}
/*
* Sets up NetworkConfigService.
*/
private void setUpNetworkConfigService() {
ApplicationId routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID);
expect(networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS)).
expect(networkConfigService.getConfig(
anyObject(ApplicationId.class), eq(RoutingService.ROUTER_CONFIG_CLASS))).
andReturn(routerConfig);
replay(networkConfigService);
}
......@@ -210,41 +184,41 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest {
* Sets up FlowObjectiveService.
*/
private void setUpFlowObjectiveService() {
expect(flowObjectiveService.allocateNextId()).andReturn(11);
expect(flowObjectiveService.allocateNextId()).andReturn(NEXT_ID);
replay(flowObjectiveService);
}
/**
* Tests adding a FIB entry to the flowObjectiveService.
* Creates a next objective with the given parameters.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flow is submitted to the flowObjectiveService.
* @param srcMac source MAC address
* @param dstMac destination MAC address
* @param port port number
* @param vlan vlan ID
* @param add whether to create an add objective or remove objective
* @return new next objective
*/
@Test
public void testFibAdd() {
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
FibEntry fibEntry = new FibEntry(prefix,
Ip4Address.valueOf("192.168.10.1"),
MacAddress.valueOf("00:00:00:00:00:01"));
//create the next Objective
Interface egressIntf = interfaceService.getMatchingInterface(fibEntry.nextHopIp());
private NextObjective createNextObjective(MacAddress srcMac,
MacAddress dstMac,
PortNumber port,
VlanId vlan,
boolean add) {
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
.setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
.setEthDst(MacAddress.valueOf("00:00:00:00:00:01"));
.setEthSrc(srcMac)
.setEthDst(dstMac);
TrafficSelector.Builder metabuilder = null;
if (!egressIntf.vlan().equals(VlanId.NONE)) {
if (!vlan.equals(VlanId.NONE)) {
treatment.pushVlan()
.setVlanId(egressIntf.vlan())
.setVlanId(vlan)
.setVlanPcp((byte) 0);
} else {
metabuilder = DefaultTrafficSelector.builder();
metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN));
}
treatment.setOutput(PortNumber.portNumber(1));
int nextId = 11;
treatment.setOutput(port);
NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
.withId(nextId)
.withId(NEXT_ID)
.addTreatment(treatment.build())
.withType(NextObjective.Type.SIMPLE)
.fromApp(APPID);
......@@ -252,10 +226,18 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest {
nextBuilder.withMeta(metabuilder.build());
}
NextObjective nextObjective = nextBuilder.add();
flowObjectiveService.next(deviceId, nextObjective);
return add ? nextBuilder.add() : nextBuilder.remove();
}
//set up the flowObjective
/**
* Creates a new forwarding objective with the given parameters.
*
* @param prefix IP prefix
* @param add whether to create an add objective or a remove objective
* @return new forwarding objective
*/
private ForwardingObjective createForwardingObjective(IpPrefix prefix,
boolean add) {
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(prefix)
......@@ -269,260 +251,134 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest {
.withPriority(priority)
.withFlag(ForwardingObjective.Flag.SPECIFIC);
Integer nextId1 = 11;
fwdBuilder.nextStep(nextId1);
flowObjectiveService.forward(deviceId, fwdBuilder.add());
if (add) {
fwdBuilder.nextStep(NEXT_ID);
} else {
fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
}
return add ? fwdBuilder.add() : fwdBuilder.remove();
}
/**
* Tests adding a route.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flow is submitted to the flowObjectiveService.
*/
@Test
public void testRouteAdd() {
ResolvedRoute resolvedRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
flowObjectiveService.next(DEVICE_ID, nextObjective);
// Create the flow objective
ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
flowObjectiveService.forward(DEVICE_ID, fwd);
EasyMock.expectLastCall().once();
setUpFlowObjectiveService();
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
// Send in the add event
RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
routeListener.event(routeEvent);
verify(flowObjectiveService);
}
/**
* Tests adding a FIB entry with to a next hop in a VLAN.
* Tests adding a route with to a next hop in a VLAN.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flowObjectiveService is submitted to the flowObjectiveService.
*/
@Test
public void testFibAddWithVlan() {
IpPrefix prefix = Ip4Prefix.valueOf("3.3.3.0/24");
FibEntry fibEntry = new FibEntry(prefix,
Ip4Address.valueOf("192.168.40.1"),
MacAddress.valueOf("00:00:00:00:00:04"));
//create the next Objective
Interface egressIntf = interfaceService.getMatchingInterface(fibEntry.nextHopIp());
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
.setEthSrc(MacAddress.valueOf("00:00:00:00:00:04"))
.setEthDst(MacAddress.valueOf("00:00:00:00:00:04"));
TrafficSelector.Builder metabuilder = null;
if (!egressIntf.vlan().equals(VlanId.NONE)) {
treatment.pushVlan()
.setVlanId(egressIntf.vlan())
.setVlanPcp((byte) 0);
} else {
metabuilder = DefaultTrafficSelector.builder();
metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN));
}
treatment.setOutput(PortNumber.portNumber(1));
int nextId = 11;
NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
.withId(nextId)
.addTreatment(treatment.build())
.withType(NextObjective.Type.SIMPLE)
.fromApp(APPID);
if (metabuilder != null) {
nextBuilder.withMeta(metabuilder.build());
}
NextObjective nextObjective = nextBuilder.add();
flowObjectiveService.next(deviceId, nextObjective);
//set up the flowObjective
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(prefix)
.build();
public void testRouteAddWithVlan() {
ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2);
int priority = prefix.prefixLength() * 5 + 100;
ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
.fromApp(APPID)
.makePermanent()
.withSelector(selector)
.withPriority(priority)
.withFlag(ForwardingObjective.Flag.SPECIFIC);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
flowObjectiveService.next(DEVICE_ID, nextObjective);
Integer nextId1 = 11;
fwdBuilder.nextStep(nextId1);
flowObjectiveService.forward(deviceId, fwdBuilder.add());
// Create the flow objective
ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
flowObjectiveService.forward(DEVICE_ID, fwd);
EasyMock.expectLastCall().once();
setUpFlowObjectiveService();
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
// Send in the add event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
verify(flowObjectiveService);
}
/**
* Tests updating a FIB entry.
* Tests updating a route.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flow is submitted to the flowObjectiveService.
*/
@Test
public void testFibUpdate() {
public void testRouteUpdate() {
// Firstly add a route
testFibAdd();
testRouteAdd();
reset(flowObjectiveService);
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
// Start to construct a new route entry and new intent
FibEntry fibEntryUpdate = new FibEntry(prefix,
Ip4Address.valueOf("192.168.20.1"),
MacAddress.valueOf("00:00:00:00:00:02"));
//create the next Objective
Interface egressIntf = interfaceService.getMatchingInterface(fibEntryUpdate.nextHopIp());
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
.setEthSrc(MacAddress.valueOf("00:00:00:00:00:02"))
.setEthDst(MacAddress.valueOf("00:00:00:00:00:02"));
TrafficSelector.Builder metabuilder = null;
if (!egressIntf.vlan().equals(VlanId.NONE)) {
treatment.pushVlan()
.setVlanId(egressIntf.vlan())
.setVlanPcp((byte) 0);
} else {
metabuilder = DefaultTrafficSelector.builder();
metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN));
}
treatment.setOutput(PortNumber.portNumber(1));
int nextId = 11;
NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
.withId(nextId)
.addTreatment(treatment.build())
.withType(NextObjective.Type.SIMPLE)
.fromApp(APPID);
if (metabuilder != null) {
nextBuilder.withMeta(metabuilder.build());
}
NextObjective nextObjective = nextBuilder.add();
flowObjectiveService.next(deviceId, nextObjective);
//set up the flowObjective
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(prefix)
.build();
ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2);
int priority = prefix.prefixLength() * 5 + 100;
ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
.fromApp(APPID)
.makePermanent()
.withSelector(selector)
.withPriority(priority)
.withFlag(ForwardingObjective.Flag.SPECIFIC);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
flowObjectiveService.next(DEVICE_ID, nextObjective);
Integer nextId1 = 11;
fwdBuilder.nextStep(nextId1);
flowObjectiveService.forward(deviceId, fwdBuilder.add());
// Create the flow objective
ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
flowObjectiveService.forward(DEVICE_ID, fwd);
EasyMock.expectLastCall().once();
setUpFlowObjectiveService();
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE,
fibEntryUpdate);
fibListener.update(Collections.singletonList(fibUpdate),
Collections.emptyList());
// Send in the update event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route));
verify(flowObjectiveService);
}
/**
* Tests deleting a FIB entry.
* Tests deleting a route.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flow is withdrawn from the flowObjectiveService.
*/
@Test
public void testFibDelete() {
public void testRouteDelete() {
// Firstly add a route
testFibAdd();
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
// Construct the existing route entry
FibEntry fibEntry = new FibEntry(prefix, null, null);
//set up the flowObjective
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(prefix)
.build();
testRouteAdd();
int priority = prefix.prefixLength() * 5 + 100;
// Construct the existing route
ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null);
ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
.fromApp(APPID)
.makePermanent()
.withSelector(selector)
.withPriority(priority)
.withFlag(ForwardingObjective.Flag.SPECIFIC);
fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
// Create the flow objective
reset(flowObjectiveService);
flowObjectiveService.forward(deviceId, fwdBuilder.remove());
ForwardingObjective fwd = createForwardingObjective(PREFIX1, false);
flowObjectiveService.forward(DEVICE_ID, fwd);
replay(flowObjectiveService);
// Send in the DELETE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry);
fibListener.update(Collections.emptyList(), Collections.singletonList(fibUpdate));
// Send in the delete event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
verify(flowObjectiveService);
}
private class TestInterfaceService extends InterfaceServiceAdapter {
@Override
public void addListener(InterfaceListener listener) {
SingleSwitchFibInstallerTest.this.interfaceListener = listener;
}
@Override
public Set<Interface> getInterfaces() {
return interfaces;
}
@Override
public Set<Interface> getInterfacesByPort(ConnectPoint port) {
Set<Interface> setIntf = new HashSet<Interface>();
for (Interface intf : interfaces) {
if (intf.connectPoint().equals(port)) {
setIntf.add(intf);
}
}
return setIntf;
interfaceListener = listener;
}
@Override
public Interface getMatchingInterface(IpAddress ip) {
Interface intff = null;
for (Interface intf : interfaces) {
for (InterfaceIpAddress address : intf.ipAddresses()) {
if (address.ipAddress().equals(ip)) {
intff = intf;
break;
}
}
}
return intff;
}
}
private class TestCoreService extends CoreServiceAdapter {
@Override
public ApplicationId getAppId(String name) {
return APPID;
}
@Override
public ApplicationId registerApplication(String name) {
return APPID;
}
}
private class TestRoutingService extends RoutingServiceAdapter {
private class TestRouteService extends RouteServiceAdapter {
@Override
public void addFibListener(FibListener fibListener) {
SingleSwitchFibInstallerTest.this.fibListener = fibListener;
public void addListener(RouteListener listener) {
SingleSwitchFibInstallerTest.this.routeListener = listener;
}
}
......@@ -532,9 +388,7 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest {
public List<String> getInterfaces() {
ArrayList<String> interfaces = new ArrayList<>();
interfaces.add("of:0000000000000001/1");
interfaces.add("of:0000000000000002/1");
interfaces.add("of:0000000000000003/1");
interfaces.add("of:0000000000000004/1");
interfaces.add("of:0000000000000001/2");
return interfaces;
}
......
......@@ -73,7 +73,6 @@ public class SdnIp {
private static List<String> components = new ArrayList<>();
static {
components.add("org.onosproject.routing.bgp.BgpSessionManager");
components.add("org.onosproject.routing.impl.Router");
components.add(org.onosproject.sdnip.SdnIpFib.class.getName());
}
......
......@@ -34,6 +34,10 @@ import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceEvent;
import org.onosproject.incubator.net.intf.InterfaceListener;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.incubator.net.routing.ResolvedRoute;
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
......@@ -43,21 +47,15 @@ import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.constraint.PartialFailureConstraint;
import org.onosproject.routing.FibListener;
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.IntentSynchronizationService;
import org.onosproject.routing.RoutingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkArgument;
/**
* FIB component of SDN-IP.
*/
......@@ -75,9 +73,9 @@ public class SdnIpFib {
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RoutingService routingService;
protected RouteService routeService;
private final InternalFibListener fibListener = new InternalFibListener();
private final InternalRouteListener routeListener = new InternalRouteListener();
private final InternalInterfaceListener interfaceListener = new InternalInterfaceListener();
private static final int PRIORITY_OFFSET = 100;
......@@ -96,69 +94,41 @@ public class SdnIpFib {
interfaceService.addListener(interfaceListener);
routingService.addFibListener(fibListener);
routingService.start();
routeService.addListener(routeListener);
}
@Deactivate
public void deactivate() {
interfaceService.removeListener(interfaceListener);
// TODO remove listener
routingService.stop();
routeService.removeListener(routeListener);
}
private void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) {
int submitCount = 0, withdrawCount = 0;
//
// NOTE: Semantically, we MUST withdraw existing intents before
// submitting new intents.
//
private void update(ResolvedRoute route) {
synchronized (this) {
MultiPointToSinglePointIntent intent;
//
// Prepare the Intent batch operations for the intents to withdraw
//
for (FibUpdate withdraw : withdraws) {
checkArgument(withdraw.type() == FibUpdate.Type.DELETE,
"FibUpdate with wrong type in withdraws list");
IpPrefix prefix = route.prefix();
MultiPointToSinglePointIntent intent =
generateRouteIntent(prefix, route.nextHop(), route.nextHopMac());
IpPrefix prefix = withdraw.entry().prefix();
intent = routeIntents.remove(prefix);
if (intent == null) {
log.trace("SDN-IP No intent in routeIntents to delete " +
"for prefix: {}", prefix);
continue;
}
intentSynchronizer.withdraw(intent);
withdrawCount++;
}
//
// Prepare the Intent batch operations for the intents to submit
//
for (FibUpdate update : updates) {
checkArgument(update.type() == FibUpdate.Type.UPDATE,
"FibUpdate with wrong type in updates list");
IpPrefix prefix = update.entry().prefix();
intent = generateRouteIntent(prefix, update.entry().nextHopIp(),
update.entry().nextHopMac());
if (intent == null) {
// This preserves the old semantics - if an intent can't be
// generated, we don't do anything with that prefix. But
// perhaps we should withdraw the old intent anyway?
continue;
log.debug("SDN-IP no interface found for route {}", route);
return;
}
routeIntents.put(prefix, intent);
intentSynchronizer.submit(intent);
submitCount++;
}
}
log.debug("SDN-IP submitted {}/{}, withdrew = {}/{}", submitCount,
updates.size(), withdrawCount, withdraws.size());
private void withdraw(ResolvedRoute route) {
synchronized (this) {
IpPrefix prefix = route.prefix();
MultiPointToSinglePointIntent intent = routeIntents.remove(prefix);
if (intent == null) {
log.trace("SDN-IP no intent in routeIntents to delete " +
"for prefix: {}", prefix);
return;
}
intentSynchronizer.withdraw(intent);
}
}
......@@ -292,10 +262,20 @@ public class SdnIpFib {
}
}
private class InternalFibListener implements FibListener {
private class InternalRouteListener implements RouteListener {
@Override
public void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) {
SdnIpFib.this.update(updates, withdraws);
public void event(RouteEvent event) {
switch (event.type()) {
case ROUTE_ADDED:
case ROUTE_UPDATED:
update(event.subject());
break;
case ROUTE_REMOVED:
withdraw(event.subject());
break;
default:
break;
}
}
}
......
......@@ -23,7 +23,6 @@ import org.junit.Test;
import org.onlab.packet.Ethernet;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -35,6 +34,10 @@ import org.onosproject.incubator.net.intf.InterfaceEvent;
import org.onosproject.incubator.net.intf.InterfaceListener;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
import org.onosproject.incubator.net.routing.ResolvedRoute;
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteServiceAdapter;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
......@@ -46,11 +49,7 @@ import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.routing.FibEntry;
import org.onosproject.routing.FibListener;
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.IntentSynchronizationService;
import org.onosproject.routing.RoutingServiceAdapter;
import java.util.Collections;
import java.util.HashSet;
......@@ -81,10 +80,6 @@ public class SdnIpFibTest extends AbstractIntentTest {
DeviceId.deviceId("of:0000000000000002"),
PortNumber.portNumber(1));
private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000003"),
PortNumber.portNumber(1));
private static final ConnectPoint SW4_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000004"),
PortNumber.portNumber(1));
......@@ -93,13 +88,15 @@ public class SdnIpFibTest extends AbstractIntentTest {
DeviceId.deviceId("of:0000000000000005"),
PortNumber.portNumber(1));
private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
private SdnIpFib sdnipFib;
private IntentSynchronizationService intentSynchronizer;
private final Set<Interface> interfaces = Sets.newHashSet();
private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
private FibListener fibListener;
private RouteListener routeListener;
private InterfaceListener interfaceListener;
@Before
......@@ -118,7 +115,7 @@ public class SdnIpFibTest extends AbstractIntentTest {
intentSynchronizer = createMock(IntentSynchronizationService.class);
sdnipFib = new SdnIpFib();
sdnipFib.routingService = new TestRoutingService();
sdnipFib.routeService = new TestRouteService();
sdnipFib.coreService = new TestCoreService();
sdnipFib.interfaceService = interfaceService;
sdnipFib.intentSynchronizer = intentSynchronizer;
......@@ -131,45 +128,24 @@ public class SdnIpFibTest extends AbstractIntentTest {
*/
private void setUpInterfaceService() {
List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
interfaceIpAddresses1.add(new InterfaceIpAddress(
IpAddress.valueOf("192.168.10.101"),
IpPrefix.valueOf("192.168.10.0/24")));
interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24"));
Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1,
interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
VlanId.NONE);
interfaces.add(sw1Eth1);
List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
interfaceIpAddresses2.add(
new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
IpPrefix.valueOf("192.168.20.0/24")));
interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24"));
Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1,
interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
VlanId.NONE);
interfaces.add(sw2Eth1);
List<InterfaceIpAddress> interfaceIpAddresses3 = Lists.newArrayList();
interfaceIpAddresses3.add(
new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
IpPrefix.valueOf("192.168.30.0/24")));
Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1,
interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"),
VlanId.NONE);
interfaces.add(sw3Eth1);
InterfaceIpAddress interfaceIpAddress4 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"),
IpPrefix.valueOf("192.168.40.0/24"));
InterfaceIpAddress interfaceIpAddress4 = InterfaceIpAddress.valueOf("192.168.40.101/24");
Interface sw4Eth1 = new Interface("sw4-eth1", SW4_ETH1,
Lists.newArrayList(interfaceIpAddress4),
MacAddress.valueOf("00:00:00:00:00:04"),
VlanId.vlanId((short) 1));
expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn(
Collections.singleton(sw4Eth1)).anyTimes();
expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1")))
.andReturn(sw4Eth1).anyTimes();
interfaces.add(sw4Eth1);
expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
......@@ -180,31 +156,29 @@ public class SdnIpFibTest extends AbstractIntentTest {
Collections.singleton(sw2Eth1)).anyTimes();
expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
.andReturn(sw2Eth1).anyTimes();
expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
Collections.singleton(sw3Eth1)).anyTimes();
expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
.andReturn(sw3Eth1).anyTimes();
expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn(
Collections.singleton(sw4Eth1)).anyTimes();
expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1")))
.andReturn(sw4Eth1).anyTimes();
expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
}
/**
* Tests adding a FIB entry to the IntentSynchronizer.
* Tests adding a route.
*
* We verify that the synchronizer records the correct state and that the
* correct intent is submitted to the IntentService.
*/
@Test
public void testFibAdd() {
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
FibEntry fibEntry = new FibEntry(prefix,
public void testRouteAdd() {
ResolvedRoute route = new ResolvedRoute(PREFIX1,
Ip4Address.valueOf("192.168.10.1"),
MacAddress.valueOf("00:00:00:00:00:01"));
// Construct a MultiPointToSinglePointIntent intent
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
fibEntry.prefix());
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1);
TrafficTreatment.Builder treatmentBuilder =
DefaultTrafficTreatment.builder();
......@@ -212,13 +186,12 @@ public class SdnIpFibTest extends AbstractIntentTest {
Set<ConnectPoint> ingressPoints = new HashSet<>();
ingressPoints.add(SW2_ETH1);
ingressPoints.add(SW3_ETH1);
ingressPoints.add(SW4_ETH1);
MultiPointToSinglePointIntent intent =
MultiPointToSinglePointIntent.builder()
.appId(APPID)
.key(Key.of(prefix.toString(), APPID))
.key(Key.of(PREFIX1.toString(), APPID))
.selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
......@@ -230,23 +203,21 @@ public class SdnIpFibTest extends AbstractIntentTest {
intentSynchronizer.submit(eqExceptId(intent));
replay(intentSynchronizer);
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
// Send in the added event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
verify(intentSynchronizer);
}
/**
* Tests adding a FIB entry with to a next hop in a VLAN.
* Tests adding a route with to a next hop in a VLAN.
*
* We verify that the synchronizer records the correct state and that the
* correct intent is submitted to the IntentService.
*/
@Test
public void testFibAddWithVlan() {
IpPrefix prefix = Ip4Prefix.valueOf("3.3.3.0/24");
FibEntry fibEntry = new FibEntry(prefix,
public void testRouteAddWithVlan() {
ResolvedRoute route = new ResolvedRoute(PREFIX1,
Ip4Address.valueOf("192.168.40.1"),
MacAddress.valueOf("00:00:00:00:00:04"));
......@@ -254,7 +225,7 @@ public class SdnIpFibTest extends AbstractIntentTest {
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(fibEntry.prefix())
.matchIPDst(PREFIX1)
.matchVlanId(VlanId.ANY);
TrafficTreatment.Builder treatmentBuilder =
......@@ -265,12 +236,11 @@ public class SdnIpFibTest extends AbstractIntentTest {
Set<ConnectPoint> ingressPoints = new HashSet<>();
ingressPoints.add(SW1_ETH1);
ingressPoints.add(SW2_ETH1);
ingressPoints.add(SW3_ETH1);
MultiPointToSinglePointIntent intent =
MultiPointToSinglePointIntent.builder()
.appId(APPID)
.key(Key.of(prefix.toString(), APPID))
.key(Key.of(PREFIX1.toString(), APPID))
.selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
......@@ -283,36 +253,32 @@ public class SdnIpFibTest extends AbstractIntentTest {
replay(intentSynchronizer);
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList());
// Send in the added event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
verify(intentSynchronizer);
}
/**
* Tests updating a FIB entry.
* Tests updating a route.
*
* We verify that the synchronizer records the correct state and that the
* correct intent is submitted to the IntentService.
*/
@Test
public void testFibUpdate() {
public void testRouteUpdate() {
// Firstly add a route
testFibAdd();
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
testRouteAdd();
// Start to construct a new route entry and new intent
FibEntry fibEntryUpdate = new FibEntry(prefix,
ResolvedRoute route = new ResolvedRoute(PREFIX1,
Ip4Address.valueOf("192.168.20.1"),
MacAddress.valueOf("00:00:00:00:00:02"));
// Construct a new MultiPointToSinglePointIntent intent
TrafficSelector.Builder selectorBuilderNew =
DefaultTrafficSelector.builder();
selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
fibEntryUpdate.prefix());
selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1);
TrafficTreatment.Builder treatmentBuilderNew =
DefaultTrafficTreatment.builder();
......@@ -320,13 +286,12 @@ public class SdnIpFibTest extends AbstractIntentTest {
Set<ConnectPoint> ingressPointsNew = new HashSet<>();
ingressPointsNew.add(SW1_ETH1);
ingressPointsNew.add(SW3_ETH1);
ingressPointsNew.add(SW4_ETH1);
MultiPointToSinglePointIntent intentNew =
MultiPointToSinglePointIntent.builder()
.appId(APPID)
.key(Key.of(prefix.toString(), APPID))
.key(Key.of(PREFIX1.toString(), APPID))
.selector(selectorBuilderNew.build())
.treatment(treatmentBuilderNew.build())
.ingressPoints(ingressPointsNew)
......@@ -341,36 +306,30 @@ public class SdnIpFibTest extends AbstractIntentTest {
intentSynchronizer.submit(eqExceptId(intentNew));
replay(intentSynchronizer);
// Send in the UPDATE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE,
fibEntryUpdate);
fibListener.update(Collections.singletonList(fibUpdate),
Collections.emptyList());
// Send in the update event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route));
verify(intentSynchronizer);
}
/**
* Tests deleting a FIB entry.
* Tests deleting a route.
*
* We verify that the synchronizer records the correct state and that the
* correct intent is withdrawn from the IntentService.
*/
@Test
public void testFibDelete() {
public void testRouteDelete() {
// Firstly add a route
testFibAdd();
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
testRouteAdd();
// Construct the existing route entry
FibEntry fibEntry = new FibEntry(prefix, null, null);
ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null);
// Construct the existing MultiPointToSinglePoint intent
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(
fibEntry.prefix());
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1);
TrafficTreatment.Builder treatmentBuilder =
DefaultTrafficTreatment.builder();
......@@ -378,13 +337,12 @@ public class SdnIpFibTest extends AbstractIntentTest {
Set<ConnectPoint> ingressPoints = new HashSet<>();
ingressPoints.add(SW2_ETH1);
ingressPoints.add(SW3_ETH1);
ingressPoints.add(SW4_ETH1);
MultiPointToSinglePointIntent addedIntent =
MultiPointToSinglePointIntent.builder()
.appId(APPID)
.key(Key.of(prefix.toString(), APPID))
.key(Key.of(PREFIX1.toString(), APPID))
.selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
......@@ -398,23 +356,20 @@ public class SdnIpFibTest extends AbstractIntentTest {
intentSynchronizer.withdraw(eqExceptId(addedIntent));
replay(intentSynchronizer);
// Send in the DELETE FibUpdate
FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry);
fibListener.update(Collections.emptyList(), Collections.singletonList(fibUpdate));
// Send in the removed event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
verify(intentSynchronizer);
}
@Test
public void testAddInterface() {
testFibAdd();
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
testRouteAdd();
// Construct the existing MultiPointToSinglePoint intent
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix);
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1);
TrafficTreatment.Builder treatmentBuilder =
DefaultTrafficTreatment.builder();
......@@ -422,14 +377,13 @@ public class SdnIpFibTest extends AbstractIntentTest {
Set<ConnectPoint> ingressPoints = new HashSet<>();
ingressPoints.add(SW2_ETH1);
ingressPoints.add(SW3_ETH1);
ingressPoints.add(SW4_ETH1);
ingressPoints.add(SW5_ETH1);
MultiPointToSinglePointIntent addedIntent =
MultiPointToSinglePointIntent.builder()
.appId(APPID)
.key(Key.of(prefix.toString(), APPID))
.key(Key.of(PREFIX1.toString(), APPID))
.selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
......@@ -455,14 +409,12 @@ public class SdnIpFibTest extends AbstractIntentTest {
@Test
public void testRemoveInterface() {
testFibAdd();
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
testRouteAdd();
// Construct the existing MultiPointToSinglePoint intent
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix);
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1);
TrafficTreatment.Builder treatmentBuilder =
DefaultTrafficTreatment.builder();
......@@ -470,12 +422,11 @@ public class SdnIpFibTest extends AbstractIntentTest {
Set<ConnectPoint> ingressPoints = new HashSet<>();
ingressPoints.add(SW2_ETH1);
ingressPoints.add(SW3_ETH1);
MultiPointToSinglePointIntent addedIntent =
MultiPointToSinglePointIntent.builder()
.appId(APPID)
.key(Key.of(prefix.toString(), APPID))
.key(Key.of(PREFIX1.toString(), APPID))
.selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
......@@ -506,16 +457,14 @@ public class SdnIpFibTest extends AbstractIntentTest {
}
}
private class TestRoutingService extends RoutingServiceAdapter {
private class TestRouteService extends RouteServiceAdapter {
@Override
public void addFibListener(FibListener fibListener) {
SdnIpFibTest.this.fibListener = fibListener;
public void addListener(RouteListener routeListener) {
SdnIpFibTest.this.routeListener = routeListener;
}
}
private class InterfaceServiceDelegate extends InterfaceServiceAdapter {
@Override
public void addListener(InterfaceListener listener) {
SdnIpFibTest.this.interfaceListener = listener;
......
......@@ -49,7 +49,6 @@ public class Vrouter {
private final List<String> components = ImmutableList.<String>builder()
.add("org.onosproject.routing.fpm.FpmManager")
.add("org.onosproject.routing.impl.Router")
.add("org.onosproject.routing.impl.SingleSwitchFibInstaller")
.add("org.onosproject.routing.impl.ControlPlaneRedirectManager")
.build();
......
......@@ -182,11 +182,6 @@ public class InterfaceIpAddress {
@Override
public String toString() {
/*return toStringHelper(this).add("ipAddress", ipAddress)
.add("subnetAddress", subnetAddress)
.add("broadcastAddress", broadcastAddress)
.add("peerAddress", peerAddress)
.omitNullValues().toString();*/
return ipAddress.toString() + "/" + subnetAddress.prefixLength();
}
}
......