本文整理汇总了Java中net.floodlightcontroller.packet.IPv4.getPayload方法的典型用法代码示例。如果您正苦于以下问题:Java IPv4.getPayload方法的具体用法?Java IPv4.getPayload怎么用?Java IPv4.getPayload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.packet.IPv4
的用法示例。
在下文中一共展示了IPv4.getPayload方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
private VerificationPacket deserialize(Ethernet eth) throws Exception {
if (eth.getPayload() instanceof IPv4) {
IPv4 ip = (IPv4) eth.getPayload();
if (ip.getPayload() instanceof UDP) {
UDP udp = (UDP) ip.getPayload();
if ((udp.getSourcePort().getPort() == PathVerificationService.VERIFICATION_PACKET_UDP_PORT)
&& (udp.getDestinationPort()
.getPort() == PathVerificationService.VERIFICATION_PACKET_UDP_PORT)) {
return new VerificationPacket((Data) udp.getPayload());
}
}
}
throw new Exception("Ethernet packet was not a verification packet");
}
示例2: snoopDHCPClientName
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
/**
* Snoop and record client-provided host name from DHCP requests
* @param eth
* @param srcDevice
*/
private void snoopDHCPClientName(Ethernet eth, Device srcDevice) {
if (! (eth.getPayload() instanceof IPv4) )
return;
IPv4 ipv4 = (IPv4) eth.getPayload();
if (! (ipv4.getPayload() instanceof UDP) )
return;
UDP udp = (UDP) ipv4.getPayload();
if (!(udp.getPayload() instanceof DHCP))
return;
DHCP dhcp = (DHCP) udp.getPayload();
byte opcode = dhcp.getOpCode();
if (opcode == DHCP.OPCODE_REQUEST) {
DHCPOption dhcpOption = dhcp.getOption(
DHCPOptionCode.OptionCode_Hostname);
if (dhcpOption != null) {
cntDhcpClientNameSnooped.increment();
srcDevice.dhcpClientName = new String(dhcpOption.getData());
}
}
}
示例3: snoopDHCPClientName
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
/**
* Snoop and record client-provided host name from DHCP requests
* @param eth
* @param srcDevice
*/
private void snoopDHCPClientName(Ethernet eth, Device srcDevice) {
if (! (eth.getPayload() instanceof IPv4) )
return;
IPv4 ipv4 = (IPv4) eth.getPayload();
if (! (ipv4.getPayload() instanceof UDP) )
return;
UDP udp = (UDP) ipv4.getPayload();
if (!(udp.getPayload() instanceof DHCP))
return;
DHCP dhcp = (DHCP) udp.getPayload();
byte opcode = dhcp.getOpCode();
if (opcode == DHCP.OPCODE_REQUEST) {
DHCPOption dhcpOption = dhcp.getOption(
DHCPOptionCode.OptionCode_Hostname);
if (dhcpOption != null) {
cntDhcpClientNameSnooped.updateCounterNoFlush();
srcDevice.dhcpClientName = new String(dhcpOption.getData());
}
}
}
示例4: getDstPort
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的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;
}
}
示例5: getSrcPort
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的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;
}
}
示例6: getUnicityDiff
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
/**
* returns the minimum of the difference between the unicity distance and the number of mask usages for each link of the route using the current mask ID
* @param mask_id
* @param route
* @return
*/
public float getUnicityDiff(Ethernet packet, Route route) {
IPv4 ip_pkt = (IPv4) packet.getPayload();
int dst_port = 0;
if (ip_pkt.getPayload() instanceof TCP)
dst_port = ((TCP)ip_pkt.getPayload()).getDestinationPort().getPort();
if (ip_pkt.getPayload() instanceof UDP)
dst_port = ((UDP)ip_pkt.getPayload()).getDestinationPort().getPort();
long dst = ObfuscationPolicy.getEndpointIdentifier(false, packet.getDestinationMACAddress().getLong(), ip_pkt.getDestinationAddress().getInt(), dst_port);
return getUnicityDiff(dst, route);
}
示例7: processTCP
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的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;
}
示例8: processPacketIn
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
private net.floodlightcontroller.core.IListener.Command processPacketIn(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPacket pkt = eth.getPayload();
if (eth.isBroadcast() || eth.isMulticast()) {
// handle ARP for VIP
if (pkt instanceof ARP) {
// retrieve arp to determine target IP address
ARP arpRequest = (ARP) eth.getPayload();
IPv4Address targetProtocolAddress = arpRequest.getTargetProtocolAddress();
if (vipIpToId.containsKey(targetProtocolAddress.getInt())) {
String vipId = vipIpToId.get(targetProtocolAddress.getInt());
vipProxyArpReply(sw, pi, cntx, vipId);
return Command.STOP;
}
}
} else {
// currently only load balance IPv4 packets - no-op for other traffic
if (pkt instanceof IPv4) {
IPv4 ip_pkt = (IPv4) pkt;
// If match Vip and port, check pool and choose member
int destIpAddress = ip_pkt.getDestinationAddress().getInt();
if (vipIpToId.containsKey(destIpAddress)){
IPClient client = new IPClient();
client.ipAddress = ip_pkt.getSourceAddress();
client.nw_proto = ip_pkt.getProtocol();
if (ip_pkt.getPayload() instanceof TCP) {
TCP tcp_pkt = (TCP) ip_pkt.getPayload();
client.srcPort = tcp_pkt.getSourcePort();
client.targetPort = tcp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof UDP) {
UDP udp_pkt = (UDP) ip_pkt.getPayload();
client.srcPort = udp_pkt.getSourcePort();
client.targetPort = udp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof ICMP) {
client.srcPort = TransportPort.of(8);
client.targetPort = TransportPort.of(0);
}
LBVip vip = vips.get(vipIpToId.get(destIpAddress));
if (vip == null) // fix dereference violations
return Command.CONTINUE;
LBPool pool = pools.get(vip.pickPool(client));
if (pool == null) // fix dereference violations
return Command.CONTINUE;
LBMember member = members.get(pool.pickMember(client));
if(member == null) //fix dereference violations
return Command.CONTINUE;
// for chosen member, check device manager and find and push routes, in both directions
pushBidirectionalVipRoutes(sw, pi, cntx, client, member);
// packet out based on table rule
pushPacket(pkt, sw, pi.getBufferId(), (pi.getVersion().compareTo(OFVersion.OF_12) < 0) ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT), OFPort.TABLE,
cntx, true);
return Command.STOP;
}
}
}
// bypass non-load-balanced traffic for normal processing (forwarding)
return Command.CONTINUE;
}
示例9: createMatchFromPacket
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的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();
}
示例10: processPacketIn
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
private net.floodlightcontroller.core.IListener.Command processPacketIn(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPacket pkt = eth.getPayload();
if (eth.isBroadcast() || eth.isMulticast()) {
// handle ARP for VIP
if (pkt instanceof ARP) {
// retrieve arp to determine target IP address
ARP arpRequest = (ARP) eth.getPayload();
int targetProtocolAddress = IPv4.toIPv4Address(arpRequest
.getTargetProtocolAddress());
if (vipIpToId.containsKey(targetProtocolAddress)) {
String vipId = vipIpToId.get(targetProtocolAddress);
vipProxyArpReply(sw, pi, cntx, vipId);
return Command.STOP;
}
}
} else {
// currently only load balance IPv4 packets - no-op for other traffic
if (pkt instanceof IPv4) {
IPv4 ip_pkt = (IPv4) pkt;
// If match Vip and port, check pool and choose member
int destIpAddress = ip_pkt.getDestinationAddress().getInt();
if (vipIpToId.containsKey(destIpAddress)){
IPClient client = new IPClient();
client.ipAddress = ip_pkt.getSourceAddress();
client.nw_proto = ip_pkt.getProtocol();
if (ip_pkt.getPayload() instanceof TCP) {
TCP tcp_pkt = (TCP) ip_pkt.getPayload();
client.srcPort = tcp_pkt.getSourcePort();
client.targetPort = tcp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof UDP) {
UDP udp_pkt = (UDP) ip_pkt.getPayload();
client.srcPort = udp_pkt.getSourcePort();
client.targetPort = udp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof ICMP) {
client.srcPort = TransportPort.of(8);
client.targetPort = TransportPort.of(0);
}
LBVip vip = vips.get(vipIpToId.get(destIpAddress));
LBPool pool = pools.get(vip.pickPool(client));
LBMember member = members.get(pool.pickMember(client));
// for chosen member, check device manager and find and push routes, in both directions
pushBidirectionalVipRoutes(sw, pi, cntx, client, member);
// packet out based on table rule
pushPacket(pkt, sw, pi.getBufferId(), (pi.getVersion().compareTo(OFVersion.OF_12) < 0) ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT), OFPort.TABLE,
cntx, true);
return Command.STOP;
}
}
}
// bypass non-load-balanced traffic for normal processing (forwarding)
return Command.CONTINUE;
}
示例11: processPacketIn
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
private net.floodlightcontroller.core.IListener.Command
processPacketIn(IOFSwitch sw, OFPacketIn pi,
FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPacket pkt = eth.getPayload();
if (eth.isBroadcast() || eth.isMulticast()) {
// handle ARP for VIP
if (pkt instanceof ARP) {
// retrieve arp to determine target IP address
ARP arpRequest = (ARP) eth.getPayload();
int targetProtocolAddress = IPv4.toIPv4Address(arpRequest
.getTargetProtocolAddress());
if (vipIpToId.containsKey(targetProtocolAddress)) {
String vipId = vipIpToId.get(targetProtocolAddress);
vipProxyArpReply(sw, pi, cntx, vipId);
return Command.STOP;
}
}
} else {
// currently only load balance IPv4 packets - no-op for other traffic
if (pkt instanceof IPv4) {
IPv4 ip_pkt = (IPv4) pkt;
// If match Vip and port, check pool and choose member
int destIpAddress = ip_pkt.getDestinationAddress();
if (vipIpToId.containsKey(destIpAddress)){
IPClient client = new IPClient();
client.ipAddress = ip_pkt.getSourceAddress();
client.nw_proto = ip_pkt.getProtocol();
if (ip_pkt.getPayload() instanceof TCP) {
TCP tcp_pkt = (TCP) ip_pkt.getPayload();
client.srcPort = tcp_pkt.getSourcePort();
client.targetPort = tcp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof UDP) {
UDP udp_pkt = (UDP) ip_pkt.getPayload();
client.srcPort = udp_pkt.getSourcePort();
client.targetPort = udp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof ICMP) {
client.srcPort = 8;
client.targetPort = 0;
}
LBVip vip = vips.get(vipIpToId.get(destIpAddress));
LBPool pool = pools.get(vip.pickPool(client));
LBMember member = members.get(pool.pickMember(client));
// for chosen member, check device manager and find and push routes, in both directions
pushBidirectionalVipRoutes(sw, pi, cntx, client, member);
// packet out based on table rule
pushPacket(pkt, sw, pi.getBufferId(), pi.getInPort(), OFPort.OFPP_TABLE.getValue(),
cntx, true);
return Command.STOP;
}
}
}
// bypass non-load-balanced traffic for normal processing (forwarding)
return Command.CONTINUE;
}
示例12: processPacketIn
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
private net.floodlightcontroller.core.IListener.Command processPacketIn(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPacket pkt = eth.getPayload();
if (eth.isBroadcast() || eth.isMulticast()) {
// handle ARP for VIP
if (pkt instanceof ARP) {
// retrieve arp to determine target IP address
ARP arpRequest = (ARP) eth.getPayload();
IPv4Address targetProtocolAddress = arpRequest.getTargetProtocolAddress();
if (vipIpToId.containsKey(targetProtocolAddress.getInt())) {
String vipId = vipIpToId.get(targetProtocolAddress.getInt());
vipProxyArpReply(sw, pi, cntx, vipId);
return Command.STOP;
}
}
} else {
// currently only load balance IPv4 packets - no-op for other traffic
if (pkt instanceof IPv4) {
IPv4 ip_pkt = (IPv4) pkt;
// If match Vip and port, check pool and choose member
int destIpAddress = ip_pkt.getDestinationAddress().getInt();
if (vipIpToId.containsKey(destIpAddress)){
IPClient client = new IPClient();
client.ipAddress = ip_pkt.getSourceAddress();
client.nw_proto = ip_pkt.getProtocol();
if (ip_pkt.getPayload() instanceof TCP) {
TCP tcp_pkt = (TCP) ip_pkt.getPayload();
client.srcPort = tcp_pkt.getSourcePort();
client.targetPort = tcp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof UDP) {
UDP udp_pkt = (UDP) ip_pkt.getPayload();
client.srcPort = udp_pkt.getSourcePort();
client.targetPort = udp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof ICMP) {
client.srcPort = TransportPort.of(8);
client.targetPort = TransportPort.of(0);
}
LBVip vip = vips.get(vipIpToId.get(destIpAddress));
if (vip == null) // fix dereference violations
return Command.CONTINUE;
LBPool pool = pools.get(vip.pickPool(client));
if (pool == null) // fix dereference violations
return Command.CONTINUE;
LBMember member = members.get(pool.pickMember(client));
if(member == null) //fix dereference violations
return Command.CONTINUE;
// for chosen member, check device manager and find and push routes, in both directions
pushBidirectionalVipRoutes(sw, pi, cntx, client, member);
// packet out based on table rule
pushPacket(pkt, sw, pi.getBufferId(), (pi.getVersion().compareTo(OFVersion.OF_12) < 0) ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT), OFPort.TABLE,
cntx, true);
return Command.STOP;
}
}
}
// bypass non-load-balanced traffic for normal processing (forwarding)
return Command.CONTINUE;
}