Package org.openflow.protocol

Examples of org.openflow.protocol.OFPacketOut


    }

    @Test
    public void testFlood() throws Exception {
        // build our expected flooded packetOut
        OFPacketOut po = new OFPacketOut()
            .setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
            .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
            .setBufferId(-1)
            .setInPort((short)1)
            .setPacketData(this.testPacketSerialized);
        po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU()
                + this.testPacketSerialized.length);

        // Mock up our expected behavior
        IOFSwitch mockSwitch = createMock(IOFSwitch.class);
        expect(mockSwitch.getStringId()).andReturn("00:11:22:33:44:55:66:77").anyTimes();
View Full Code Here


        ofAcOut.setMaxLength((short) -1);
        ofAcOut.setPort((short)2);
        ofAcOut.setLength((short) 8);
        ofAcOut.setType(OFActionType.OUTPUT);

        OFPacketOut packetOut = new OFPacketOut();
        packetOut.setActions(Arrays.asList(new OFAction[] {ofAcOut}))
        .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
        .setBufferId(50)
        .setInPort((short)1)
        .setPacketData(null)
        .setLength((short) (OFPacketOut.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH));
        packetOut.setActionFactory(mockFloodlightProvider.getOFMessageFactory());

        // Mock up our expected behavior
        IOFSwitch mockSwitch = createMock(IOFSwitch.class);
        expect(mockSwitch.getId()).andReturn(1L).anyTimes();
        expect(mockSwitch.getAttribute(IOFSwitch.PROP_FASTWILDCARDS)).andReturn((OFMatch.OFPFW_IN_PORT | OFMatch.OFPFW_NW_PROTO
View Full Code Here

            ethernet.setPayload(bsn);
        }

        // serialize and wrap in a packet out
        byte[] data = ethernet.serialize();
        OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory()
                                                         .getMessage(OFType.PACKET_OUT);
        po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
        po.setInPort(OFPort.OFPP_NONE);

        // set data and data length
        po.setLengthU(OFPacketOut.MINIMUM_LENGTH + data.length);
        po.setPacketData(data);

        return po;
    }
View Full Code Here

        if (log.isTraceEnabled()) {
            log.trace("Sending LLDP packet out of swich: {}, port: {}",
                      HexString.toHexString(sw), port);
        }
        OFPacketOut po = generateLLDPMessage(sw, port, isStandard, isReverse);

        // Add actions
        List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort);
        po.setActions(actions);
        short  actionLength = 0;
        Iterator <OFAction> actionIter = actions.iterator();
        while (actionIter.hasNext()) {
            actionLength += actionIter.next().getLength();
        }
        po.setActionsLength(actionLength);

        // po already has the minimum length + data length set
        // simply add the actions length to this.
        po.setLengthU(po.getLengthU() + po.getActionsLength());

        // send
        try {
            iofSwitch.write(po, null);
            iofSwitch.flush();
View Full Code Here

        if (log.isTraceEnabled()) {
            log.trace("PacketOut srcSwitch={} match={} pi={}",
                      new Object[] {sw, match, pi});
        }

        OFPacketOut po =
                (OFPacketOut) floodlightProvider.getOFMessageFactory()
                                                .getMessage(OFType.PACKET_OUT);

        // set actions
        List<OFAction> actions = new ArrayList<OFAction>();
        actions.add(new OFActionOutput(outport, (short) 0xffff));

        po.setActions(actions)
          .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);
        short poLength =
                (short) (po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH);

        // If the switch doens't support buffering set the buffer id to be none
        // otherwise it'll be the the buffer id of the PacketIn
        if (sw.getBuffers() == 0) {
            // We set the PI buffer id here so we don't have to check again below
            pi.setBufferId(OFPacketOut.BUFFER_ID_NONE);
            po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
        } else {
            po.setBufferId(pi.getBufferId());
        }

        po.setInPort(pi.getInPort());

        // If the buffer id is none or the switch doesn's support buffering
        // we send the data with the packet out
        if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
            byte[] packetData = pi.getPacketData();
            poLength += packetData.length;
            po.setPacketData(packetData);
        }

        po.setLength(poLength);

        try {
            counterStore.updatePktOutFMCounterStoreLocal(sw, po);
            sw.write(po, null);
        } catch (IOException e) {
View Full Code Here

        // struct ofp_action_header actions[0]; /* Actions. */
        /* uint8_t data[0]; */ /* Packet data. The length is inferred
                                  from the length field in the header.
                                  (Only meaningful if buffer_id == -1.) */

        OFPacketOut packetOutMessage = (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
        short packetOutLength = (short)OFPacketOut.MINIMUM_LENGTH; // starting length

        // Set buffer_id, in_port, actions_len
        packetOutMessage.setBufferId(packetInMessage.getBufferId());
        packetOutMessage.setInPort(packetInMessage.getInPort());
        packetOutMessage.setActionsLength((short)OFActionOutput.MINIMUM_LENGTH);
        packetOutLength += OFActionOutput.MINIMUM_LENGTH;

        // set actions
        List<OFAction> actions = new ArrayList<OFAction>(1);
        actions.add(new OFActionOutput(egressPort, (short) 0));
        packetOutMessage.setActions(actions);

        // set data - only if buffer_id == -1
        if (packetInMessage.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
            byte[] packetData = packetInMessage.getPacketData();
            packetOutMessage.setPacketData(packetData);
            packetOutLength += (short)packetData.length;
        }

        // finally, set the total length
        packetOutMessage.setLength(packetOutLength);

        // and write it out
        try {
            counterStore.updatePktOutFMCounterStoreLocal(sw, packetOutMessage);
            sw.write(packetOutMessage, null);
View Full Code Here

     byte[] icmpPacket1Serialized, icmpPacket2Serialized;

     OFPacketIn arpRequestPacketIn1;
     OFPacketIn icmpPacketIn1, icmpPacketIn2;

     OFPacketOut arpReplyPacketOut1;

     Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
     Capture<FloodlightContext> bc1 =
             new Capture<FloodlightContext>(CaptureType.ALL);

     int fastWildcards =
             OFMatch.OFPFW_IN_PORT |
             OFMatch.OFPFW_NW_PROTO |
             OFMatch.OFPFW_TP_SRC |
             OFMatch.OFPFW_TP_DST |
             OFMatch.OFPFW_NW_SRC_ALL |
             OFMatch.OFPFW_NW_DST_ALL |
             OFMatch.OFPFW_NW_TOS;

     sw1 = EasyMock.createNiceMock(IOFSwitch.class);
     expect(sw1.getId()).andReturn(1L).anyTimes();
     expect(sw1.getStringId()).andReturn("00:00:00:00:00:01").anyTimes();
     expect(sw1.getAttribute(IOFSwitch.PROP_FASTWILDCARDS)).andReturn(fastWildcards).anyTimes();
     expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
     sw1.writeThrottled(capture(wc1), capture(bc1));
     expectLastCall().anyTimes();
     sw1.flush();
     expectLastCall().anyTimes();

     replay(sw1);
     sfp.switchAdded(1L);
     verify(sw1);

     /* Test plan:
      * - two clients and two servers on sw1 port 1, 2, 3, 4
      * - mock arp request received towards vip1 from (1L, 1)
      * - proxy arp got pushed out to (1L, 1)- check sw1 getting the packetout
      * - mock icmp request received towards vip1 from (1L, 1)
      * - device manager list of devices queried to identify source and dest devices
      * - routing engine queried to get inbound and outbound routes
      * - check getRoute calls and responses
      * - sfp called to install flows
      * - check sfp calls
      */

     // Build topology
     reset(topology);
     expect(topology.isIncomingBroadcastAllowed(anyLong(), anyShort())).andReturn(true).anyTimes();
     expect(topology.getL2DomainId(1L)).andReturn(1L).anyTimes();
     expect(topology.isAttachmentPointPort(1L, (short)1)).andReturn(true).anyTimes();
     expect(topology.isAttachmentPointPort(1L, (short)2)).andReturn(true).anyTimes();
     expect(topology.isAttachmentPointPort(1L, (short)3)).andReturn(true).anyTimes();
     expect(topology.isAttachmentPointPort(1L, (short)4)).andReturn(true).anyTimes();
     replay(topology);



     // Build arp packets
     arpRequest1 = new Ethernet()
     .setSourceMACAddress("00:00:00:00:00:01")
     .setDestinationMACAddress("ff:ff:ff:ff:ff:ff")
     .setEtherType(Ethernet.TYPE_ARP)
     .setVlanID((short) 0)
     .setPriorityCode((byte) 0)
     .setPayload(
         new ARP()
         .setHardwareType(ARP.HW_TYPE_ETHERNET)
         .setProtocolType(ARP.PROTO_TYPE_IP)
         .setHardwareAddressLength((byte) 6)
         .setProtocolAddressLength((byte) 4)
         .setOpCode(ARP.OP_REQUEST)
         .setSenderHardwareAddress(HexString.fromHexString("00:00:00:00:00:01"))
         .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("10.0.0.1"))
         .setTargetHardwareAddress(HexString.fromHexString("00:00:00:00:00:00"))
         .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("10.0.0.100")));

     arpRequest1Serialized = arpRequest1.serialize();

     arpRequestPacketIn1 =
             ((OFPacketIn) getMockFloodlightProvider().getOFMessageFactory().
                     getMessage(OFType.PACKET_IN))
                     .setBufferId(-1)
                     .setInPort((short) 1)
                     .setPacketData(arpRequest1Serialized)
                     .setReason(OFPacketInReason.NO_MATCH)
                     .setTotalLength((short) arpRequest1Serialized.length);

     IFloodlightProviderService.bcStore.put(cntx,
                                            IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
                                            (Ethernet) arpRequest1);

     // Mock proxy arp packet-out
     arpReply1 = new Ethernet()
     .setSourceMACAddress(LBVip.LB_PROXY_MAC)
     .setDestinationMACAddress(HexString.fromHexString("00:00:00:00:00:01"))
     .setEtherType(Ethernet.TYPE_ARP)
     .setVlanID((short) 0)
     .setPriorityCode((byte) 0)
     .setPayload(
         new ARP()
         .setHardwareType(ARP.HW_TYPE_ETHERNET)
         .setProtocolType(ARP.PROTO_TYPE_IP)
         .setHardwareAddressLength((byte) 6)
         .setProtocolAddressLength((byte) 4)
         .setOpCode(ARP.OP_REPLY)
         .setSenderHardwareAddress(HexString.fromHexString(LBVip.LB_PROXY_MAC))
         .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("10.0.0.100"))
         .setTargetHardwareAddress(HexString.fromHexString("00:00:00:00:00:01"))
         .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("10.0.0.1")));

     arpReply1Serialized = arpReply1.serialize();

     arpReplyPacketOut1 =
             (OFPacketOut) getMockFloodlightProvider().getOFMessageFactory().
                 getMessage(OFType.PACKET_OUT);
     arpReplyPacketOut1.setBufferId(OFPacketOut.BUFFER_ID_NONE)
         .setInPort(OFPort.OFPP_NONE.getValue());
     List<OFAction> poactions = new ArrayList<OFAction>();
     poactions.add(new OFActionOutput(arpRequestPacketIn1.getInPort(), (short) 0xffff));
     arpReplyPacketOut1.setActions(poactions)
         .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
         .setPacketData(arpReply1Serialized)
         .setLengthU(OFPacketOut.MINIMUM_LENGTH+
                     arpReplyPacketOut1.getActionsLength()+
                     arpReply1Serialized.length);

     lb.receive(sw1, arpRequestPacketIn1, cntx);
     verify(sw1, topology);

View Full Code Here

                .setPacketData(testPacketSerialized)
                .setReason(OFPacketInReason.NO_MATCH)
                .setTotalLength((short) testPacketSerialized.length);

        // Mock Packet-out
        OFPacketOut packetOut =
                (OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
        packetOut.setBufferId(pi.getBufferId())
        .setInPort(pi.getInPort());
        List<OFAction> poactions = new ArrayList<OFAction>();
        poactions.add(new OFActionOutput(OFPort.OFPP_TABLE.getValue(), (short) 0));
        packetOut.setActions(poactions)
        .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
        .setPacketData(testPacketSerialized)
        .setLengthU(OFPacketOut.MINIMUM_LENGTH+packetOut.getActionsLength()+testPacketSerialized.length);

        FloodlightContext cntx = new FloodlightContext();
        IFloodlightProviderService.bcStore.put(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD, (Ethernet) testPacket);

View Full Code Here

                }
            }

            // Send a packet out
            if (outPort == null || pi.getBufferId() == 0xffffffff) {
                OFPacketOut po = new OFPacketOut();
                po.setBufferId(bufferId);
                po.setInPort(pi.getInPort());

                // set actions
                OFActionOutput action = new OFActionOutput();
                action.setMaxLength((short) 0);
                action.setPort((short) ((outPort == null) ? OFPort.OFPP_FLOOD
                        .getValue() : outPort));
                List<OFAction> actions = new ArrayList<OFAction>();
                actions.add(action);
                po.setActions(actions);
                po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);

                // set data if needed
                if (bufferId == 0xffffffff) {
                    byte[] packetData = pi.getPacketData();
                    po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
                            + po.getActionsLength() + packetData.length));
                    po.setPacketData(packetData);
                } else {
                    po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
                            + po.getActionsLength()));
                }
                try {
                    stream.write(po);
                } catch (IOException e) {
                    e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.openflow.protocol.OFPacketOut

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.