/** * Create an OFFlowMod that can be passed to StaticEntryPusher. * * @param sw switch object * @param match match for the flow * @param meter meter for the flow * @param actions actions for the flow * @param cookie cookie for the flow * @param priority priority to set on the flow * @return {@link OFFlowMod} */ private OFFlowMod buildFlowMod(final IOFSwitch sw, final Match match, final OFInstructionMeter meter, final OFInstructionApplyActions actions, final long cookie, final int priority) { OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setBufferId(OFBufferId.NO_BUFFER); fmb.setCookie(U64.of(cookie)); fmb.setPriority(priority); List<OFInstruction> instructions = new ArrayList<>(2); if (meter != null) { // If no meter then no bandwidth limit instructions.add(meter); } if (actions != null) { // If no instruction then Drops packet instructions.add(actions); } if (match != null) { // If no then match everything fmb.setMatch(match); } return fmb.setInstructions(instructions).build(); }
default OFFlowAdd transitFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(singletonList( ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
default OFFlowAdd oneSwitchNoneFlowMod(int inputPort, int outputPort, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(singletonList( ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
default OFFlowAdd oneSwitchPopFlowMod(int inputPort, int outputPort, int inputVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressPopFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().popVlan(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressNoneFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowMod buildFlowDel() { Match match = buildMatch(); long cookie = flowRule().id().value(); OFFlowDeleteStrict fm = factory().buildFlowDeleteStrict() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .setTableId(TableId.of(flowRule().tableId())) .build(); return fm; }
@Override public OFFlowAdd buildFlowAdd() { Match match = buildMatch(); List<OFAction> actions = buildActions(); long cookie = flowRule().id().value(); OFFlowAdd fm = factory().buildFlowAdd() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setActions(actions) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .build(); return fm; }
@Override public OFFlowMod buildFlowMod() { Match match = buildMatch(); List<OFAction> actions = buildActions(); long cookie = flowRule().id().value(); OFFlowMod fm = factory().buildFlowModify() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setActions(actions) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .build(); return fm; }
@Override public OFFlowDelete buildFlowDel() { Match match = buildMatch(); long cookie = flowRule().id().value(); OFFlowDelete fm = factory().buildFlowDelete() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .build(); return fm; }
private OFFlowMod createFRESCOFlowMod(IOFSwitch sw, Match match, List<OFAction> actions, int priority){ OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd();; fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setBufferId(OFBufferId.NO_BUFFER); fmb.setOutPort(OFPort.ANY); fmb.setCookie(U64.of(0)); fmb.setPriority(U16.t(priority)); fmb.setMatch(match); fmb.setActions(actions); return fmb.build(); }
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) { OFPacketIn pi = (OFPacketIn) msg; OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut(); pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT))); // set actions OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput(); actionBuilder.setPort(OFPort.FLOOD); pob.setActions(Collections.singletonList((OFAction) actionBuilder.build())); // set data if it is included in the packetin if (pi.getBufferId() == OFBufferId.NO_BUFFER) { byte[] packetData = pi.getData(); pob.setData(packetData); } return pob.build(); }
private OFPacketIn createPacketIn(String srcMAC, String dstMAC, String srcIp, String dstIp, short vlan) { IPacket testPacket = new Ethernet() .setDestinationMACAddress(dstMAC) .setSourceMACAddress(srcMAC) .setVlanID(vlan) .setEtherType(EthType.IPv4) .setPayload( new IPv4() .setTtl((byte) 128) .setSourceAddress(srcIp) .setDestinationAddress(dstIp) .setPayload(new UDP() .setSourcePort((short) 5000) .setDestinationPort((short) 5001) .setPayload(new Data(new byte[] {0x01})))); byte[] testPacketSerialized = testPacket.serialize(); OFPacketIn pi; // build out input packet pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setData(testPacketSerialized) .setReason(OFPacketInReason.NO_MATCH) .build(); return pi; }
private void sendArpReply(MacAddress senderMac, IPv4Address senderIp, MacAddress targetMac, IPv4Address targetIp, IOFSwitch sw, OFPort port) { IPacket arpReply = new Ethernet() .setSourceMACAddress(senderMac) .setDestinationMACAddress(targetMac) .setEtherType(EthType.ARP) .setPayload( new ARP() .setHardwareType(ARP.HW_TYPE_ETHERNET) .setProtocolType(ARP.PROTO_TYPE_IP) .setHardwareAddressLength((byte) 6) .setProtocolAddressLength((byte) 4) .setOpCode(ARP.OP_REPLY) .setSenderHardwareAddress(senderMac.getBytes()) .setSenderProtocolAddress(senderIp.getBytes()) .setTargetHardwareAddress(targetMac.getBytes()) .setTargetProtocolAddress(targetIp.getBytes())); pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ANY, port); }
/** * Writes an OFPacketOut message to a switch. * @param sw The switch to write the PacketOut to. * @param packetInMessage The corresponding PacketIn. * @param egressPort The switchport to output the PacketOut. */ private void writePacketOutForPacketIn(IOFSwitch sw, OFPacketIn packetInMessage, OFPort egressPort) { OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut(); // Set buffer_id, in_port, actions_len pob.setBufferId(packetInMessage.getBufferId()); pob.setInPort(packetInMessage.getVersion().compareTo(OFVersion.OF_12) < 0 ? packetInMessage.getInPort() : packetInMessage.getMatch().get(MatchField.IN_PORT)); // set actions List<OFAction> actions = new ArrayList<OFAction>(1); actions.add(sw.getOFFactory().actions().buildOutput().setPort(egressPort).setMaxLen(0xffFFffFF).build()); pob.setActions(actions); // set data - only if buffer_id == -1 if (packetInMessage.getBufferId() == OFBufferId.NO_BUFFER) { byte[] packetData = packetInMessage.getData(); pob.setData(packetData); } // and write it out counterPacketOut.increment(); sw.write(pob.build()); }
public void returnPacketToSwitch(IOFSwitch sw, OFPacketIn pi, ArrayList<OFAction> actionList) { OFPacketOut.Builder po = sw.getOFFactory().buildPacketOut(); po.setBufferId(pi.getBufferId()).setInPort(OFPort.ANY).setActions(actionList); // Packet might be buffered in the switch or encapsulated in Packet-In if (pi.getBufferId() == OFBufferId.NO_BUFFER) { //Packet is encapsulated -> send it back byte[] packetData = pi.getData(); po.setData(packetData); } log.info("PACKETOUT : returning packet back to the switch"); sw.write(po.build()); }
default OFFlowAdd oneSwitchReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
default OFFlowAdd oneSwitchPushFlowMod(int inputPort, int outputPort, int outputVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(transitVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlan, int outputVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(transitVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd ingressNoMatchVlanIdFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(transitVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlan, int outputVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public void build(OFPort outPort) { if (isBuilt.getAndSet(true)) { return; } OFPacketOut.Builder builder = sw.factory().buildPacketOut(); OFAction act = buildOutput(outPort.getPortNumber()); pktout = builder.setXid(pktin.getXid()) .setInPort(pktinInPort()) .setBufferId(OFBufferId.NO_BUFFER) .setData(pktin.getData()) // .setBufferId(pktin.getBufferId()) .setActions(Collections.singletonList(act)) .build(); }
@Override public void build(Ethernet ethFrame, OFPort outPort) { if (isBuilt.getAndSet(true)) { return; } OFPacketOut.Builder builder = sw.factory().buildPacketOut(); OFAction act = buildOutput(outPort.getPortNumber()); pktout = builder.setXid(pktin.getXid()) .setBufferId(OFBufferId.NO_BUFFER) .setInPort(pktinInPort()) .setActions(Collections.singletonList(act)) .setData(ethFrame.serialize()) .build(); }
private OFPacketOut packetOut(OpenFlowSwitch sw, byte[] eth, OFPort out) { OFPacketOut.Builder builder = sw.factory().buildPacketOut(); OFAction act = sw.factory().actions() .buildOutput() .setPort(out) .build(); return builder .setBufferId(OFBufferId.NO_BUFFER) .setInPort(OFPort.CONTROLLER) .setActions(Collections.singletonList(act)) .setData(eth) .build(); }
@Test public void handlePacket() { OFPacketIn pkt = sw.factory().buildPacketIn() .setBufferId(OFBufferId.NO_BUFFER) .setInPort(OFPort.NO_MASK) .setReason(OFPacketInReason.INVALID_TTL) .build(); controller.processPacket(null, pkt); assertNotNull("message unprocessed", registry.ctx); }
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) { OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); Match m = createMatchFromPacket(sw, inPort, cntx); OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); // this will be a drop-flow; a flow that will not output to any ports List<OFAction> actions = new ArrayList<OFAction>(); // set no action to drop U64 cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); log.info("Droppingggg"); fmb.setCookie(cookie) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(m) .setPriority(FLOWMOD_DEFAULT_PRIORITY); FlowModUtils.setActions(fmb, actions, sw); try { if (log.isDebugEnabled()) { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] { sw, m, fmb.build() }); } boolean dampened = messageDamper.write(sw, fmb.build()); log.debug("OFMessage dampened: {}", dampened); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } }
/** * Creates a OFPacketOut with the OFPacketIn data that is flooded on all ports unless * the port is blocked, in which case the packet will be dropped. * @param sw The switch that receives the OFPacketIn * @param pi The OFPacketIn that came to the switch * @param cntx The FloodlightContext associated with this OFPacketIn */ protected void doFlood(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) { OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); // Set Action to flood OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut(); List<OFAction> actions = new ArrayList<OFAction>(); Set<OFPort> broadcastPorts = this.topologyService.getSwitchBroadcastPorts(sw.getId()); if (broadcastPorts == null) { log.debug("BroadcastPorts returned null. Assuming single switch w/no links."); /* Must be a single-switch w/no links */ broadcastPorts = Collections.singleton(OFPort.FLOOD); } for (OFPort p : broadcastPorts) { if (p.equals(inPort)) continue; actions.add(sw.getOFFactory().actions().output(p, Integer.MAX_VALUE)); } pob.setActions(actions); // log.info("actions {}",actions); // set buffer-id, in-port and packet-data based on packet-in pob.setBufferId(OFBufferId.NO_BUFFER); pob.setInPort(inPort); pob.setData(pi.getData()); try { if (log.isTraceEnabled()) { log.trace("Writing flood PacketOut switch={} packet-in={} packet-out={}", new Object[] {sw, pi, pob.build()}); } messageDamper.write(sw, pob.build()); } catch (IOException e) { log.error("Failure writing PacketOut switch={} packet-in={} packet-out={}", new Object[] {sw, pi, pob.build()}, e); } return; }