Java 类org.projectfloodlight.openflow.protocol.match.MatchField 实例源码

项目:open-kilda    文件:OutputCommands.java   
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();
}
项目:open-kilda    文件:OutputCommands.java   
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();
}
项目:open-kilda    文件:OutputCommands.java   
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();
}
项目:open-kilda    文件:PushSchemeOutputCommands.java   
@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();
}
项目:open-kilda    文件:PushSchemeOutputCommands.java   
@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();
}
项目:open-kilda    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:athena    文件:OfOpticalSwitchImplLinc13.java   
/**
 * Rewrite match object to use LINC OF optical extensions.
 *
 * @param match original match
 * @return rewritten match
 */
private Match rewriteMatch(Match match) {
    Match.Builder mBuilder = factory().buildMatch();
    for (MatchField mf : match.getMatchFields()) {
        if (mf == MatchField.EXP_OCH_SIG_ID) {
            mBuilder.setExact(MatchField.OCH_SIGID, (CircuitSignalID) match.get(mf));
            continue;
        }
        if (mf == MatchField.EXP_OCH_SIGTYPE) {
            mBuilder.setExact(MatchField.OCH_SIGTYPE, (U8) match.get(mf));
            continue;
        }
        mBuilder.setExact(mf, match.get(mf));
    }

    return mBuilder.build();
}
项目:fresco_floodlight    文件:Hub.java   
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();  
}
项目:fresco_floodlight    文件:LearningSwitch.java   
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
    // The packet in match will only contain the port number.
    // We need to add in specifics for the hosts we're routing between.
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    MacAddress srcMac = eth.getSourceMACAddress();
    MacAddress dstMac = eth.getDestinationMACAddress();

    Match.Builder mb = sw.getOFFactory().buildMatch();
    mb.setExact(MatchField.IN_PORT, inPort)
    .setExact(MatchField.ETH_SRC, srcMac)
    .setExact(MatchField.ETH_DST, dstMac);

    if (!vlan.equals(VlanVid.ZERO)) {
        mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
    }

    return mb.build();
}
项目:fresco_floodlight    文件:MatchUtils.java   
/**
 * Create a point-to-point match for two devices at the IP layer.
 * Takes an existing match (e.g. from a PACKET_IN), and masks all
 * MatchFields leaving behind:
 *      IN_PORT
 *      VLAN_VID
 *      ETH_TYPE
 *      ETH_SRC
 *      ETH_DST
 *      IPV4_SRC
 *      IPV4_DST
 *      IP_PROTO (might remove this)
 * 
 * If one of the above MatchFields is wildcarded in Match m,
 * that MatchField will be wildcarded in the returned Match.
 * 
 * @param m The match to remove all L4+ MatchFields from
 * @return A new Match object with all MatchFields masked/wildcared
 * except for those listed above.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Match maskL4AndUp(Match m) {
    Match.Builder mb = m.createBuilder(); 
    Iterator<MatchField<?>> itr = m.getMatchFields().iterator(); // only get exact or masked fields (not fully wildcarded)
    while(itr.hasNext()) {
        MatchField mf = itr.next();
        // restrict MatchFields only to L3 and below: IN_PORT, ETH_TYPE, ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_PROTO (this one debatable...)
        // if a MatchField is not in the access list below, it will not be set --> it will be left wildcarded (default)
        if (mf.equals(MatchField.IN_PORT) || mf.equals(MatchField.ETH_TYPE) || mf.equals(MatchField.ETH_SRC) || mf.equals(MatchField.ETH_DST) ||
                mf.equals(MatchField.IPV4_SRC) || mf.equals(MatchField.IPV4_DST) || mf.equals(MatchField.IP_PROTO)) {
            if (m.isExact(mf)) {
                mb.setExact(mf, m.get(mf));
            } else if (m.isPartiallyMasked(mf)) {
                mb.setMasked(mf, m.getMasked(mf));
            } else {
                // it's either exact, masked, or wildcarded
                // itr only contains exact and masked MatchFields
                // we should never get here
            } 
        }
    }
    return mb.build();
}
项目:fresco_floodlight    文件:OFDPAUtils.java   
/**
 * Examine all the MatchFields in a Match object and pick out
 * the MatchFields that are not supported by OF-DPA.
 * 
 * @param m
 * @return
 */
public static List<MatchFields> checkMatchFields(Match m) {
    List<MatchFields> unsupported = null;
    Iterator<MatchField<?>> mfi = m.getMatchFields().iterator();

    while (mfi.hasNext()) {
        MatchField<?> mf = mfi.next();
        if (!getSupportedMatchFields().contains(mf.id)) {
            if (unsupported == null) {
                unsupported = new ArrayList<MatchFields>();
            }
            unsupported.add(mf.id);
        }
    }

    return unsupported;
}
项目:fresco_floodlight    文件:TopologyManager.java   
/**
 * If the packet-in switch port is disabled for all data traffic, then
 * the packet will be dropped.  Otherwise, the packet will follow the
 * normal processing chain.
 * @param sw
 * @param pi
 * @param cntx
 * @return
 */
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
        FloodlightContext cntx) {
    Command result = Command.CONTINUE;
    OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));

    // If the input port is not allowed for data traffic, drop everything.
    // BDDP packets will not reach this stage.
    if (isAllowed(sw, inPort) == false) {
        if (log.isTraceEnabled()) {
            log.trace("Ignoring packet because of topology " +
                    "restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
            result = Command.STOP;
        }
    }
    return result;
}
项目:fresco_floodlight    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:iTAP-controller    文件:ObfuscationTopologyManager.java   
public void updateTopologyMappings(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);

    if (eth.getPayload() instanceof IPv4) {
        IPv4 ip_pkt = (IPv4) eth.getPayload();

        if (ip_pkt.getSourceAddress().getInt() > 0) {
            IpToMac.put(ip_pkt.getSourceAddress(), eth.getSourceMACAddress());
            IpToSwitch.put(ip_pkt.getSourceAddress(),new SwitchHostInfo(sw,pi.getMatch().get(MatchField.IN_PORT)));
        }
    }
    else if (eth.getPayload() instanceof ARP) {
        ARP arp_pkt = (ARP) eth.getPayload();

        if (IPv4Address.of(arp_pkt.getSenderProtocolAddress()).getInt() > 0) {

            if (!IPv4Address.of(arp_pkt.getSenderProtocolAddress()).toString().contentEquals("10.0.0.111")) {// ignore crafted requests from switches 
                IpToMac.put(IPv4Address.of(arp_pkt.getSenderProtocolAddress()), eth.getSourceMACAddress());
                IpToSwitch.put(IPv4Address.of(arp_pkt.getSenderProtocolAddress()),new SwitchHostInfo(sw,pi.getMatch().get(MatchField.IN_PORT)));
            }
        }
    }
}
项目:iTAP-controller    文件:Hub.java   
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();  
}
项目:iTAP-controller    文件:LearningSwitch.java   
/**
 * 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());

}
项目:iTAP-controller    文件:LearningSwitch.java   
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
    // The packet in match will only contain the port number.
    // We need to add in specifics for the hosts we're routing between.
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    MacAddress srcMac = eth.getSourceMACAddress();
    MacAddress dstMac = eth.getDestinationMACAddress();

    Match.Builder mb = sw.getOFFactory().buildMatch();
    mb.setExact(MatchField.IN_PORT, inPort)
    .setExact(MatchField.ETH_SRC, srcMac)
    .setExact(MatchField.ETH_DST, dstMac);

    if (!vlan.equals(VlanVid.ZERO)) {
        mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
    }

    return mb.build();
}
项目:iTAP-controller    文件:MatchUtils.java   
/**
 * Create a point-to-point match for two devices at the IP layer.
 * Takes an existing match (e.g. from a PACKET_IN), and masks all
 * MatchFields leaving behind:
 *      IN_PORT
 *      VLAN_VID
 *      ETH_TYPE
 *      ETH_SRC
 *      ETH_DST
 *      IPV4_SRC
 *      IPV4_DST
 *      IP_PROTO (might remove this)
 * 
 * If one of the above MatchFields is wildcarded in Match m,
 * that MatchField will be wildcarded in the returned Match.
 * 
 * @param m The match to remove all L4+ MatchFields from
 * @return A new Match object with all MatchFields masked/wildcared
 * except for those listed above.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Match maskL4AndUp(Match m) {
    Match.Builder mb = m.createBuilder(); 
    Iterator<MatchField<?>> itr = m.getMatchFields().iterator(); // only get exact or masked fields (not fully wildcarded)
    while(itr.hasNext()) {
        MatchField mf = itr.next();
        // restrict MatchFields only to L3 and below: IN_PORT, ETH_TYPE, ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_PROTO (this one debatable...)
        // if a MatchField is not in the access list below, it will not be set --> it will be left wildcarded (default)
        if (mf.equals(MatchField.IN_PORT) || mf.equals(MatchField.ETH_TYPE) || mf.equals(MatchField.ETH_SRC) || mf.equals(MatchField.ETH_DST) ||
                mf.equals(MatchField.IPV4_SRC) || mf.equals(MatchField.IPV4_DST) || mf.equals(MatchField.IP_PROTO)) {
            if (m.isExact(mf)) {
                mb.setExact(mf, m.get(mf));
            } else if (m.isPartiallyMasked(mf)) {
                mb.setMasked(mf, m.getMasked(mf));
            } else {
                // it's either exact, masked, or wildcarded
                // itr only contains exact and masked MatchFields
                // we should never get here
            } 
        }
    }
    return mb.build();
}
项目:iTAP-controller    文件:TopologyManager.java   
/**
 * If the packet-in switch port is disabled for all data traffic, then
 * the packet will be dropped.  Otherwise, the packet will follow the
 * normal processing chain.
 * @param sw
 * @param pi
 * @param cntx
 * @return
 */
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
        FloodlightContext cntx) {
    Command result = Command.CONTINUE;
    OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));

    // If the input port is not allowed for data traffic, drop everything.
    // BDDP packets will not reach this stage.
    if (isAllowed(sw, inPort) == false) {
        if (log.isTraceEnabled()) {
            log.trace("Ignoring packet because of topology " +
                    "restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
            result = Command.STOP;
        }
    }
    return result;
}
项目:iTAP-controller    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:SDN-Multicast    文件:Hub.java   
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();  
}
项目:SDN-Multicast    文件:LearningSwitch.java   
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
    // The packet in match will only contain the port number.
    // We need to add in specifics for the hosts we're routing between.
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    MacAddress srcMac = eth.getSourceMACAddress();
    MacAddress dstMac = eth.getDestinationMACAddress();

    Match.Builder mb = sw.getOFFactory().buildMatch();
    mb.setExact(MatchField.IN_PORT, inPort)
    .setExact(MatchField.ETH_SRC, srcMac)
    .setExact(MatchField.ETH_DST, dstMac);

    if (!vlan.equals(VlanVid.ZERO)) {
        mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
    }

    return mb.build();
}
项目:floodlight-hardware    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:SDN-Multicast    文件:OFDPAUtils.java   
/**
 * Examine all the MatchFields in a Match object and pick out
 * the MatchFields that are not supported by OF-DPA.
 * 
 * @param m
 * @return
 */
public static List<MatchFields> checkMatchFields(Match m) {
    List<MatchFields> unsupported = null;
    Iterator<MatchField<?>> mfi = m.getMatchFields().iterator();

    while (mfi.hasNext()) {
        MatchField<?> mf = mfi.next();
        if (!getSupportedMatchFields().contains(mf.id)) {
            if (unsupported == null) {
                unsupported = new ArrayList<MatchFields>();
            }
            unsupported.add(mf.id);
        }
    }

    return unsupported;
}
项目:SDN-Multicast    文件:TopologyManager.java   
/**
 * If the packet-in switch port is disabled for all data traffic, then
 * the packet will be dropped.  Otherwise, the packet will follow the
 * normal processing chain.
 * @param sw
 * @param pi
 * @param cntx
 * @return
 */
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
        FloodlightContext cntx) {
    Command result = Command.CONTINUE;
    OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));

    // If the input port is not allowed for data traffic, drop everything.
    // BDDP packets will not reach this stage.
    if (isAllowed(sw, inPort) == false) {
        if (log.isTraceEnabled()) {
            log.trace("Ignoring packet because of topology " +
                    "restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
            result = Command.STOP;
        }
    }
    return result;
}
项目:ACAMPController    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:arscheduler    文件:LearningSwitch.java   
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
    // The packet in match will only contain the port number.
    // We need to add in specifics for the hosts we're routing between.
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    MacAddress srcMac = eth.getSourceMACAddress();
    MacAddress dstMac = eth.getDestinationMACAddress();

    Match.Builder mb = sw.getOFFactory().buildMatch();
    mb.setExact(MatchField.IN_PORT, inPort)
    .setExact(MatchField.ETH_SRC, srcMac)
    .setExact(MatchField.ETH_DST, dstMac);

    if (!vlan.equals(VlanVid.ZERO)) {
        mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
    }

    return mb.build();
}
项目:floodlight-hardware    文件:OFDPAUtils.java   
/**
 * Examine all the MatchFields in a Match object and pick out
 * the MatchFields that are not supported by OF-DPA.
 *
 * @param m
 * @return
 */
public static List<MatchFields> checkMatchFields(Match m) {
    List<MatchFields> unsupported = null;
    Iterator<MatchField<?>> mfi = m.getMatchFields().iterator();

    while (mfi.hasNext()) {
        MatchField<?> mf = mfi.next();
        if (!getSupportedMatchFields().contains(mf.id)) {
            if (unsupported == null) {
                unsupported = new ArrayList<MatchFields>();
            }
            unsupported.add(mf.id);
        }
    }

    return unsupported;
}
项目:ACAMPController    文件:LearningSwitch.java   
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
    // The packet in match will only contain the port number.
    // We need to add in specifics for the hosts we're routing between.
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    MacAddress srcMac = eth.getSourceMACAddress();
    MacAddress dstMac = eth.getDestinationMACAddress();

    Match.Builder mb = sw.getOFFactory().buildMatch();
    mb.setExact(MatchField.IN_PORT, inPort)
    .setExact(MatchField.ETH_SRC, srcMac)
    .setExact(MatchField.ETH_DST, dstMac);

    if (!vlan.equals(VlanVid.ZERO)) {
        mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
    }

    return mb.build();
}
项目:arscheduler    文件:MatchUtils.java   
/**
 * Create a point-to-point match for two devices at the IP layer.
 * Takes an existing match (e.g. from a PACKET_IN), and masks all
 * MatchFields leaving behind:
 *      IN_PORT
 *      VLAN_VID
 *      ETH_TYPE
 *      ETH_SRC
 *      ETH_DST
 *      IPV4_SRC
 *      IPV4_DST
 *      IP_PROTO (might remove this)
 * 
 * If one of the above MatchFields is wildcarded in Match m,
 * that MatchField will be wildcarded in the returned Match.
 * 
 * @param m The match to remove all L4+ MatchFields from
 * @return A new Match object with all MatchFields masked/wildcared
 * except for those listed above.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Match maskL4AndUp(Match m) {
    Match.Builder mb = m.createBuilder(); 
    Iterator<MatchField<?>> itr = m.getMatchFields().iterator(); // only get exact or masked fields (not fully wildcarded)
    while(itr.hasNext()) {
        MatchField mf = itr.next();
        // restrict MatchFields only to L3 and below: IN_PORT, ETH_TYPE, ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_PROTO (this one debatable...)
        // if a MatchField is not in the access list below, it will not be set --> it will be left wildcarded (default)
        if (mf.equals(MatchField.IN_PORT) || mf.equals(MatchField.ETH_TYPE) || mf.equals(MatchField.ETH_SRC) || mf.equals(MatchField.ETH_DST) ||
                mf.equals(MatchField.IPV4_SRC) || mf.equals(MatchField.IPV4_DST) || mf.equals(MatchField.IP_PROTO)) {
            if (m.isExact(mf)) {
                mb.setExact(mf, m.get(mf));
            } else if (m.isPartiallyMasked(mf)) {
                mb.setMasked(mf, m.getMasked(mf));
            } else {
                // it's either exact, masked, or wildcarded
                // itr only contains exact and masked MatchFields
                // we should never get here
            } 
        }
    }
    return mb.build();
}
项目:arscheduler    文件:OFDPAUtils.java   
/**
 * Examine all the MatchFields in a Match object and pick out
 * the MatchFields that are not supported by OF-DPA.
 * 
 * @param m
 * @return
 */
public static List<MatchFields> checkMatchFields(Match m) {
    List<MatchFields> unsupported = null;
    Iterator<MatchField<?>> mfi = m.getMatchFields().iterator();

    while (mfi.hasNext()) {
        MatchField<?> mf = mfi.next();
        if (!getSupportedMatchFields().contains(mf.id)) {
            if (unsupported == null) {
                unsupported = new ArrayList<MatchFields>();
            }
            unsupported.add(mf.id);
        }
    }

    return unsupported;
}
项目:arscheduler    文件:TopologyManager.java   
/**
 * If the packet-in switch port is disabled for all data traffic, then
 * the packet will be dropped.  Otherwise, the packet will follow the
 * normal processing chain.
 * @param sw
 * @param pi
 * @param cntx
 * @return
 */
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
        FloodlightContext cntx) {
    Command result = Command.CONTINUE;
    OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));

    // If the input port is not allowed for data traffic, drop everything.
    // BDDP packets will not reach this stage.
    if (isAllowed(sw, inPort) == false) {
        if (log.isTraceEnabled()) {
            log.trace("Ignoring packet because of topology " +
                    "restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
            result = Command.STOP;
        }
    }
    return result;
}
项目:ACAMPController    文件:MatchUtils.java   
/**
 * Create a point-to-point match for two devices at the IP layer.
 * Takes an existing match (e.g. from a PACKET_IN), and masks all
 * MatchFields leaving behind:
 *      IN_PORT
 *      VLAN_VID
 *      ETH_TYPE
 *      ETH_SRC
 *      ETH_DST
 *      IPV4_SRC
 *      IPV4_DST
 *      IP_PROTO (might remove this)
 * 
 * If one of the above MatchFields is wildcarded in Match m,
 * that MatchField will be wildcarded in the returned Match.
 * 
 * @param m The match to remove all L4+ MatchFields from
 * @return A new Match object with all MatchFields masked/wildcared
 * except for those listed above.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Match maskL4AndUp(Match m) {
    Match.Builder mb = m.createBuilder(); 
    Iterator<MatchField<?>> itr = m.getMatchFields().iterator(); // only get exact or masked fields (not fully wildcarded)
    while(itr.hasNext()) {
        MatchField mf = itr.next();
        // restrict MatchFields only to L3 and below: IN_PORT, ETH_TYPE, ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_PROTO (this one debatable...)
        // if a MatchField is not in the access list below, it will not be set --> it will be left wildcarded (default)
        if (mf.equals(MatchField.IN_PORT) || mf.equals(MatchField.ETH_TYPE) || mf.equals(MatchField.ETH_SRC) || mf.equals(MatchField.ETH_DST) ||
                mf.equals(MatchField.IPV4_SRC) || mf.equals(MatchField.IPV4_DST) || mf.equals(MatchField.IP_PROTO)) {
            if (m.isExact(mf)) {
                mb.setExact(mf, m.get(mf));
            } else if (m.isPartiallyMasked(mf)) {
                mb.setMasked(mf, m.getMasked(mf));
            } else {
                // it's either exact, masked, or wildcarded
                // itr only contains exact and masked MatchFields
                // we should never get here
            } 
        }
    }
    return mb.build();
}
项目:ACAMPController    文件:OFDPAUtils.java   
/**
 * Examine all the MatchFields in a Match object and pick out
 * the MatchFields that are not supported by OF-DPA.
 * 
 * @param m
 * @return
 */
public static List<MatchFields> checkMatchFields(Match m) {
    List<MatchFields> unsupported = null;
    Iterator<MatchField<?>> mfi = m.getMatchFields().iterator();

    while (mfi.hasNext()) {
        MatchField<?> mf = mfi.next();
        if (!getSupportedMatchFields().contains(mf.id)) {
            if (unsupported == null) {
                unsupported = new ArrayList<MatchFields>();
            }
            unsupported.add(mf.id);
        }
    }

    return unsupported;
}
项目:floodlight1.2-delay    文件:Hub.java   
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();  
}
项目:floodlight1.2-delay    文件:LearningSwitch.java   
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
    // The packet in match will only contain the port number.
    // We need to add in specifics for the hosts we're routing between.
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
    MacAddress srcMac = eth.getSourceMACAddress();
    MacAddress dstMac = eth.getDestinationMACAddress();

    Match.Builder mb = sw.getOFFactory().buildMatch();
    mb.setExact(MatchField.IN_PORT, inPort)
    .setExact(MatchField.ETH_SRC, srcMac)
    .setExact(MatchField.ETH_DST, dstMac);

    if (!vlan.equals(VlanVid.ZERO)) {
        mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
    }

    return mb.build();
}
项目:floodlight1.2-delay    文件:MatchUtils.java   
/**
 * Create a point-to-point match for two devices at the IP layer.
 * Takes an existing match (e.g. from a PACKET_IN), and masks all
 * MatchFields leaving behind:
 *      IN_PORT
 *      VLAN_VID
 *      ETH_TYPE
 *      ETH_SRC
 *      ETH_DST
 *      IPV4_SRC
 *      IPV4_DST
 *      IP_PROTO (might remove this)
 * 
 * If one of the above MatchFields is wildcarded in Match m,
 * that MatchField will be wildcarded in the returned Match.
 * 
 * @param m The match to remove all L4+ MatchFields from
 * @return A new Match object with all MatchFields masked/wildcared
 * except for those listed above.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Match maskL4AndUp(Match m) {
    Match.Builder mb = m.createBuilder(); 
    Iterator<MatchField<?>> itr = m.getMatchFields().iterator(); // only get exact or masked fields (not fully wildcarded)
    while(itr.hasNext()) {
        MatchField mf = itr.next();
        // restrict MatchFields only to L3 and below: IN_PORT, ETH_TYPE, ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_PROTO (this one debatable...)
        // if a MatchField is not in the access list below, it will not be set --> it will be left wildcarded (default)
        if (mf.equals(MatchField.IN_PORT) || mf.equals(MatchField.ETH_TYPE) || mf.equals(MatchField.ETH_SRC) || mf.equals(MatchField.ETH_DST) ||
                mf.equals(MatchField.IPV4_SRC) || mf.equals(MatchField.IPV4_DST) || mf.equals(MatchField.IP_PROTO)) {
            if (m.isExact(mf)) {
                mb.setExact(mf, m.get(mf));
            } else if (m.isPartiallyMasked(mf)) {
                mb.setMasked(mf, m.getMasked(mf));
            } else {
                // it's either exact, masked, or wildcarded
                // itr only contains exact and masked MatchFields
                // we should never get here
            } 
        }
    }
    return mb.build();
}
项目:floodlight-hardware    文件:TopologyManager.java   
/**
 * If the packet-in switch port is disabled for all data traffic, then
 * the packet will be dropped.  Otherwise, the packet will follow the
 * normal processing chain.
 * @param sw
 * @param pi
 * @param cntx
 * @return
 */
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
        FloodlightContext cntx) {
    Command result = Command.CONTINUE;
    OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));

    // If the input port is not allowed for data traffic, drop everything.
    // BDDP packets will not reach this stage.
    if (isAllowed(sw, inPort) == false) {
        if (log.isTraceEnabled()) {
            log.trace("Ignoring packet because of topology " +
                    "restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
            result = Command.STOP;
        }
    }
    return result;
}
项目:floodlight1.2-delay    文件:PacketFactory.java   
/**
 * Generates a DHCP request OFPacketIn.
 * @param hostMac The host MAC address of for the request.
 * @return An OFPacketIn that contains a DHCP request packet.
 */
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(IOFSwitch sw,
        MacAddress hostMac) {
    byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
    OFFactory factory = sw.getOFFactory();
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    if (factory.getVersion() == OFVersion.OF_10) {
        packetInBuilder
            .setInPort(OFPort.of(1))
            .setData(serializedPacket)
            .setReason(OFPacketInReason.NO_MATCH);
    } else {
        packetInBuilder
        .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
        .setData(serializedPacket)
        .setReason(OFPacketInReason.NO_MATCH);
    }
    return packetInBuilder.build();
}
项目:ACAMPController    文件:Hub.java   
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();  
}