use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class FibInstaller method addNextHop.
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(route.nextHop());
if (egressIntf == null) {
log.warn("no egress interface found for {}", route);
return;
}
NextHopGroupKey groupKey = new NextHopGroupKey(route.nextHop());
NextHop nextHop = new NextHop(route.nextHop(), route.nextHopMac(), groupKey);
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthSrc(egressIntf.mac()).setEthDst(nextHop.mac());
TrafficSelector.Builder metabuilder = null;
if (!egressIntf.vlan().equals(VlanId.NONE)) {
treatment.pushVlan().setVlanId(egressIntf.vlan()).setVlanPcp((byte) 0);
} else {
// untagged outgoing port may require internal vlan in some pipelines
metabuilder = DefaultTrafficSelector.builder();
metabuilder.matchVlanId(VlanId.vlanId(ASSIGNED_VLAN));
}
treatment.setOutput(egressIntf.connectPoint().port());
int nextId = flowObjectiveService.allocateNextId();
NextObjective.Builder nextBuilder = DefaultNextObjective.builder().withId(nextId).addTreatment(treatment.build()).withType(NextObjective.Type.SIMPLE).fromApp(fibAppId);
if (metabuilder != null) {
nextBuilder.withMeta(metabuilder.build());
}
// TODO add callbacks
NextObjective nextObjective = nextBuilder.add();
flowObjectiveService.next(deviceId, nextObjective);
nextHops.put(nextHop.ip(), nextId);
if (routeToNextHop) {
// Install route to next hop
ForwardingObjective fob = generateRibForwardingObj(IpPrefix.valueOf(route.nextHop(), 32), nextId).add();
flowObjectiveService.forward(deviceId, fob);
}
}
nextHopsCount.add(route.nextHop());
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class FibInstallerTest method testRouteAddWithVlan.
/**
* 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 testRouteAddWithVlan() {
ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, 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 add event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
verify(flowObjectiveService);
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class FibInstallerTest method testRouteAdd.
/**
* 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 = createRoute(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 add event
RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
routeListener.event(routeEvent);
verify(flowObjectiveService);
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class FibInstallerTest method testRouteDelete.
/**
* 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 testRouteDelete() {
// Firstly add a route
testRouteAdd();
// Construct the existing route
ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP1, MAC1);
// Create the flow objective
reset(flowObjectiveService);
ForwardingObjective fwd = createForwardingObjective(PREFIX1, false);
flowObjectiveService.forward(DEVICE_ID, fwd);
replay(flowObjectiveService);
// Send in the delete event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route));
verify(flowObjectiveService);
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class TunnellingConnectivityManager method notifySwitchAvailable.
/**
* Pushes the flow rules for forwarding BGP TCP packets to controller.
* It is called when switches are connected and available.
*/
public void notifySwitchAvailable() {
// control plane OVS is available, push default flows
TrafficSelector selectorDst = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDst(TpPort.tpPort(BGP_PORT)).build();
TrafficSelector selectorSrc = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpSrc(TpPort.tpPort(BGP_PORT)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
ForwardingObjective puntSrc = DefaultForwardingObjective.builder().fromApp(appId).makePermanent().withSelector(selectorSrc).withTreatment(treatment).withFlag(ForwardingObjective.Flag.VERSATILE).add();
flowObjectiveService.forward(bgpSpeaker.connectPoint().deviceId(), puntSrc);
ForwardingObjective puntDst = DefaultForwardingObjective.builder().fromApp(appId).makePermanent().withSelector(selectorDst).withTreatment(treatment).withFlag(ForwardingObjective.Flag.VERSATILE).add();
flowObjectiveService.forward(bgpSpeaker.connectPoint().deviceId(), puntDst);
log.info("Sent punt forwarding objective to {}", bgpSpeaker.connectPoint().deviceId());
}
Aggregations