本文整理汇总了Java中org.projectfloodlight.openflow.types.EthType.IPv4方法的典型用法代码示例。如果您正苦于以下问题:Java EthType.IPv4方法的具体用法?Java EthType.IPv4怎么用?Java EthType.IPv4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.projectfloodlight.openflow.types.EthType
的用法示例。
在下文中一共展示了EthType.IPv4方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSrcIP
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public int getSrcIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address srcIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
srcIP = ipv4.getSourceAddress();
return srcIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
srcIP = arp.getSenderProtocolAddress();
return srcIP.getInt();
}
//for other packets without source IP information
return 0;
}
示例2: getDstIP
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public int getDstIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address dstIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
dstIP = ipv4.getDestinationAddress();
return dstIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
dstIP = arp.getTargetProtocolAddress();
return dstIP.getInt();
}
//for other packets without destination IP information
return 0;
}
示例3: isIPv4
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public boolean isIPv4(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
return true;
}
else
{
return false;
}
}
示例4: isICMP
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public boolean isICMP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
return (ipv4.getProtocol() == IpProtocol.ICMP);
}
else
{
return false;
}
}
示例5: isTCP
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public boolean isTCP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
return (ipv4.getProtocol() == IpProtocol.TCP);
}
else
{
return false;
}
}
示例6: isUDP
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public boolean isUDP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
return (ipv4.getProtocol() == IpProtocol.UDP);
}
else
{
return false;
}
}
示例7: getDstPort
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public int getDstPort(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
if( isTCP(cntx) )
{
TCP tcp = (TCP) ipv4.getPayload();
return tcp.getDestinationPort().getPort();
}
else if ( isUDP(cntx) )
{
UDP udp = (UDP) ipv4.getPayload();
return udp.getDestinationPort().getPort();
}
else
{
return 0;
}
}
else
{
return 0;
}
}
示例8: getSrcPort
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Override
public int getSrcPort(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
if( isTCP(cntx) )
{
TCP tcp = (TCP) ipv4.getPayload();
return tcp.getSourcePort().getPort();
}
else if ( isUDP(cntx) )
{
UDP udp = (UDP) ipv4.getPayload();
return udp.getSourcePort().getPort();
}
else
{
return 0;
}
}
else
{
return 0;
}
}
示例9: testSimpleAllowRule
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Test
public void testSimpleAllowRule() throws Exception {
// enable firewall first
firewall.enableFirewall(true);
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.dl_type = EthType.IPv4;
rule.any_dl_type = false;
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
// source is IP 192.168.1.2
rule.nw_src_prefix_and_mask = IPv4AddressWithMask.of("192.168.1.2/32");
rule.any_nw_src = false;
// dest is network 192.168.1.0/24
rule.nw_dst_prefix_and_mask = IPv4AddressWithMask.of("192.168.1.0/24");
rule.any_nw_dst = false;
rule.priority = 1;
firewall.addRule(rule);
// simulate a packet-in events
this.setPacketIn(tcpPacketReply);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD, decision.getRoutingAction());
// clear decision
IRoutingDecision.rtStore.remove(cntx, IRoutingDecision.CONTEXT_DECISION);
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(IRoutingDecision.RoutingAction.DROP, decision.getRoutingAction());
}
示例10: processTCP
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
public FP_Event processTCP(FPContext cntx){
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
if (ipv4.getProtocol() == IpProtocol.TCP){
TCP tcp = (TCP) ipv4.getPayload();
short flag = tcp.getFlags();
//We assume here we have visibility of all TCP handshake messages
TCPSession session;
if (flag == 2){
session = new TCPSession(ipv4.getSourceAddress().getInt(),
tcp.getSourcePort().getPort(), ipv4.getDestinationAddress().getInt(),
tcp.getDestinationPort().getPort());
}
else{
session = new TCPSession(ipv4.getDestinationAddress().getInt(),
tcp.getDestinationPort().getPort(), ipv4.getSourceAddress().getInt(),
tcp.getSourcePort().getPort());
}
//store current TCP session into runtime context
curTCPSession.put(cntx, session);
TCPSTATE state = tcpState.get(session);
if (flag == 2){//SYN
if (state == null){
state = TCPSTATE.SYN;
session = new TCPSession(ipv4.getSourceAddress().getInt(),
tcp.getSourcePort().getPort(), ipv4.getDestinationAddress().getInt(),
tcp.getDestinationPort().getPort());
tcpState.put(session, state);
return FP_Event.TCP;
}
}
else if (flag == 16){//ACK
if (state == TCPSTATE.SYNACK){
state = TCPSTATE.ESTABLISHED;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_SUCCESS;
}
}
else if (flag == 18){ //SYNACK
if (state == TCPSTATE.SYN){
state = TCPSTATE.SYNACK;
tcpState.put(session, state);
}
}
else if (flag == 20){//RSTACK
state = TCPSTATE.OTHERS;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_FAIL;
}
// we consider other flags are TCP connection disruptions
// we will raise TCP connection disruption events
//TODO: More options to distinguish different TCP flags
else {
if (state != TCPSTATE.ESTABLISHED){
state = TCPSTATE.OTHERS;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_FAIL;
}
else{//state is TCPSTATE.ESTABLISHED
if (flag == 1){ // TCP FIN
state = TCPSTATE.OTHERS;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_FAIL;
}
}
}
return FP_Event.TCP;
}
}
return FP_Event.PACKET;
}
示例11: testOverlappingRules
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
@Test
public void testOverlappingRules() throws Exception {
firewall.enableFirewall(true);
// add TCP port 80 (destination only) allow rule
FirewallRule rule = new FirewallRule();
rule.dl_type = EthType.IPv4;
rule.any_dl_type = false;
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.tp_dst = TransportPort.of(80);
rule.priority = 1;
firewall.addRule(rule);
// add block all rule
rule = new FirewallRule();
rule.action = FirewallRule.FirewallAction.DROP;
rule.priority = 2;
firewall.addRule(rule);
assertEquals(2, firewall.rules.size());
// packet destined to TCP port 80 - should be allowed
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD);
// clear decision
IRoutingDecision.rtStore.remove(cntx, IRoutingDecision.CONTEXT_DECISION);
// packet destined for port 81 - should be denied
this.setPacketIn(tcpPacketReply);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.DROP);
}
示例12: createMatchFromPacket
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
/**
* Instead of using the Firewall's routing decision Match, which might be as general
* as "in_port" and inadvertently Match packets erroneously, construct a more
* specific Match based on the deserialized OFPacketIn's payload, which has been
* placed in the FloodlightContext already by the Controller.
*
* @param sw, the switch on which the packet was received
* @param inPort, the ingress switch port on which the packet was received
* @param cntx, the current context which contains the deserialized packet
* @return a composed Match object based on the provided information
*/
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();
// A retentive builder will remember all MatchFields of the parent the builder was generated from
// With a normal builder, all parent MatchFields will be lost if any MatchFields are added, mod, del
// TODO (This is a bug in Loxigen and the retentive builder is a workaround.)
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));
}
// TODO Detect switch type and match to create hardware-implemented flow
// TODO Set option in config file to support specific or MAC-only matches
if (eth.getEtherType() == EthType.IPv4) { /* shallow check for equality is okay for EthType */
IPv4 ip = (IPv4) eth.getPayload();
IPv4Address srcIp = ip.getSourceAddress();
IPv4Address dstIp = ip.getDestinationAddress();
mb.setExact(MatchField.IPV4_SRC, srcIp)
.setExact(MatchField.IPV4_DST, dstIp)
.setExact(MatchField.ETH_TYPE, EthType.IPv4);
if (ip.getProtocol().equals(IpProtocol.TCP)) {
TCP tcp = (TCP) ip.getPayload();
mb.setExact(MatchField.IP_PROTO, IpProtocol.TCP)
.setExact(MatchField.TCP_SRC, tcp.getSourcePort())
.setExact(MatchField.TCP_DST, tcp.getDestinationPort());
} else if (ip.getProtocol().equals(IpProtocol.UDP)) {
UDP udp = (UDP) ip.getPayload();
mb.setExact(MatchField.IP_PROTO, IpProtocol.UDP)
.setExact(MatchField.UDP_SRC, udp.getSourcePort())
.setExact(MatchField.UDP_DST, udp.getDestinationPort());
}
} else if (eth.getEtherType() == EthType.ARP) { /* shallow check for equality is okay for EthType */
mb.setExact(MatchField.ETH_TYPE, EthType.ARP);
}
return mb.build();
}
示例13: createMatchFromPacket
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
/**
* Instead of using the Firewall's routing decision Match, which might be as general
* as "in_port" and inadvertently Match packets erroneously, construct a more
* specific Match based on the deserialized OFPacketIn's payload, which has been
* placed in the FloodlightContext already by the Controller.
*
* @param sw, the switch on which the packet was received
* @param inPort, the ingress switch port on which the packet was received
* @param cntx, the current context which contains the deserialized packet
* @return a composed Match object based on the provided information
*/
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);
if (FLOWMOD_DEFAULT_MATCH_MAC) {
mb.setExact(MatchField.ETH_SRC, srcMac)
.setExact(MatchField.ETH_DST, dstMac);
}
if (FLOWMOD_DEFAULT_MATCH_VLAN) {
if (!vlan.equals(VlanVid.ZERO)) {
mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
}
}
// TODO Detect switch type and match to create hardware-implemented flow
// TODO Allow for IPv6 matches
if (eth.getEtherType() == EthType.IPv4) { /* shallow check for equality is okay for EthType */
IPv4 ip = (IPv4) eth.getPayload();
IPv4Address srcIp = ip.getSourceAddress();
IPv4Address dstIp = ip.getDestinationAddress();
if (FLOWMOD_DEFAULT_MATCH_IP_ADDR) {
mb.setExact(MatchField.ETH_TYPE, EthType.IPv4)
.setExact(MatchField.IPV4_SRC, srcIp)
.setExact(MatchField.IPV4_DST, dstIp);
}
if (FLOWMOD_DEFAULT_MATCH_TRANSPORT) {
/*
* Take care of the ethertype if not included earlier,
* since it's a prerequisite for transport ports.
*/
if (!FLOWMOD_DEFAULT_MATCH_IP_ADDR) {
mb.setExact(MatchField.ETH_TYPE, EthType.IPv4);
}
if (ip.getProtocol().equals(IpProtocol.TCP)) {
TCP tcp = (TCP) ip.getPayload();
mb.setExact(MatchField.IP_PROTO, IpProtocol.TCP)
.setExact(MatchField.TCP_SRC, tcp.getSourcePort())
.setExact(MatchField.TCP_DST, tcp.getDestinationPort());
} else if (ip.getProtocol().equals(IpProtocol.UDP)) {
UDP udp = (UDP) ip.getPayload();
mb.setExact(MatchField.IP_PROTO, IpProtocol.UDP)
.setExact(MatchField.UDP_SRC, udp.getSourcePort())
.setExact(MatchField.UDP_DST, udp.getDestinationPort());
}
}
} else if (eth.getEtherType() == EthType.ARP) { /* shallow check for equality is okay for EthType */
mb.setExact(MatchField.ETH_TYPE, EthType.ARP);
}
return mb.build();
}
示例14: buildMAEntry
import org.projectfloodlight.openflow.types.EthType; //导入方法依赖的package包/类
/**
* Build the MatchActionOperationEntry according to the flag
*
* @param sw node ID to push for MPLS label
* @param mplsLabel List of Switch DPIDs to forwards packets to
* @param fwdSws PHP flag
* @param Bos BoS flag
* @param isTransitRouter
* @return MatchiACtionOperationEntry object
*/
private MatchActionOperationEntry buildMAEntry(Switch sw,
String mplsLabel, List<String> fwdSws, boolean php,
boolean Bos) {
IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
sw.getDpid().value());
if (sw13 == null) {
return null;
}
MplsMatch mplsMatch = new MplsMatch(Integer.parseInt(mplsLabel), Bos);
List<Action> actions = new ArrayList<Action>();
PopMplsAction popActionBos = new PopMplsAction(EthType.IPv4);
PopMplsAction popAction = new PopMplsAction(EthType.MPLS_UNICAST);
CopyTtlInAction copyTtlInAction = new CopyTtlInAction();
DecNwTtlAction decNwTtlAction = new DecNwTtlAction(1);
DecMplsTtlAction decMplsTtlAction = new DecMplsTtlAction(1);
if (php) {
actions.add(copyTtlInAction);
if (Bos) {
actions.add(popActionBos);
actions.add(decNwTtlAction);
}
else {
actions.add(popAction);
actions.add(decMplsTtlAction);
}
}
else {
actions.add(decMplsTtlAction);
}
if ((sw13 instanceof OFSwitchImplDellOSR) && isTransitRouter(sw)) {
PortNumber port = pickOnePort(sw, fwdSws);
if (port == null) {
log.warn("Failed to get a port from NeightborSet");
return null;
}
OutputAction outputAction = new OutputAction(port);
Switch destSwitch =
mutableTopology.getSwitch(new Dpid(fwdSws.get(0)));
MacAddress srcMac =
MacAddress.of(sw.getStringAttribute("routerMac"));
MacAddress dstMac =
MacAddress.of(destSwitch.getStringAttribute("routerMac"));
SetSAAction setSAAction = new SetSAAction(srcMac);
SetDAAction setDAAction = new SetDAAction(dstMac);
actions.add(setSAAction);
actions.add(setDAAction);
actions.add(outputAction);
} else {
GroupAction groupAction = new GroupAction();
for (String dpid: fwdSws)
groupAction.addSwitch(new Dpid(dpid));
actions.add(groupAction);
}
MatchAction matchAction = new MatchAction(new MatchActionId(matchActionId++),
new SwitchPort((long) 0, (short) 0), mplsMatch, actions);
Operator operator = Operator.ADD;
MatchActionOperationEntry maEntry =
new MatchActionOperationEntry(operator, matchAction);
return maEntry;
}