@Test public void testEmit() { byte[] arr = new byte[10]; Device referenceDevice; DeviceEvent event; int numDevices = 10; int numInfraPorts = 5; totalPorts = 10; defaultPopulator(numDevices, numInfraPorts); for (byte byteIndex = 0; byteIndex < arr.length; byteIndex++) { arr[byteIndex] = byteIndex; } for (int i = 0; i < numDevices; i++) { referenceDevice = NetTestTools.device(Integer.toString(i)); testDeviceManager.listener.event(new DeviceEvent(DEVICE_ADDED, referenceDevice, new DefaultPort(referenceDevice, PortNumber.portNumber(1), true))); } mgr.emitPacket(ByteBuffer.wrap(arr), Optional.<TrafficTreatment>empty()); assertEquals("There were an unexpected number of emitted packets", (totalPorts - numInfraPorts) * numDevices, packets.size()); Iterator<OutboundPacket> packetIter = packets.iterator(); OutboundPacket packet; while (packetIter.hasNext()) { packet = packetIter.next(); assertEquals("The packet had an incorrect payload.", arr, packet.data().array()); } packets.clear(); mgr.emitPacket(NetTestTools.did(Integer.toString(1)), ByteBuffer.wrap(arr), Optional.<TrafficTreatment>empty()); assertEquals("Unexpected number of outbound packets were emitted.", totalPorts - numInfraPorts, packets.size()); packetIter = packets.iterator(); while (packetIter.hasNext()) { packet = packetIter.next(); assertEquals("The packet had an incorrect payload", arr, packet.data().array()); } }
@Override public void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment) { checkPermission(PACKET_WRITE); TrafficTreatment.Builder builder = treatment.map(DefaultTrafficTreatment::builder) .orElse(DefaultTrafficTreatment.builder()); getEdgePoints().forEach(p -> packetService.emit(packet(builder, p, data))); }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment) { checkPermission(PACKET_WRITE); TrafficTreatment.Builder builder = treatment.map(DefaultTrafficTreatment::builder) .orElse(DefaultTrafficTreatment.builder()); getEdgePoints().forEach(p -> packetService.emit(packet(builder, p, data))); } }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment) { checkPermission(PACKET_WRITE); TrafficTreatment.Builder builder = treatment.map(DefaultTrafficTreatment::builder) .orElse(DefaultTrafficTreatment.builder()); getEdgePoints().forEach(p -> packetService.emit(packet(builder, p, data))); }  }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment) { checkPermission(PACKET_WRITE); TrafficTreatment.Builder builder = treatment.map(DefaultTrafficTreatment::builder) .orElse(DefaultTrafficTreatment.builder()); getEdgePoints().forEach(p -> packetService.emit(packet(builder, p, data))); }  @Activate void activate(); @Deactivate void deactivate(); @Override boolean isEdgePoint(ConnectPoint point); @Override Iterable<ConnectPoint> getEdgePoints(); @Override Iterable<ConnectPoint> getEdgePoints(DeviceId deviceId); @Override void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment); @Override void emitPacket(DeviceId deviceId, ByteBuffer data,
                           Optional<TrafficTreatment> treatment); }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment) { checkPermission(PACKET_WRITE); TrafficTreatment.Builder builder = treatment.map(DefaultTrafficTreatment::builder) .orElse(DefaultTrafficTreatment.builder()); getEdgePoints().forEach(p -> packetService.emit(packet(builder, p, data))); }  @Activate void activate(); @Deactivate void deactivate(); @Override boolean isEdgePoint(ConnectPoint point); @Override Iterable<ConnectPoint> getEdgePoints(); @Override Iterable<ConnectPoint> getEdgePoints(DeviceId deviceId); @Override void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment); @Override void emitPacket(DeviceId deviceId, ByteBuffer data,
                           Optional<TrafficTreatment> treatment);  }