本文整理汇总了Java中net.floodlightcontroller.packet.UDP类的典型用法代码示例。如果您正苦于以下问题:Java UDP类的具体用法?Java UDP怎么用?Java UDP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UDP类属于net.floodlightcontroller.packet包,在下文中一共展示了UDP类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import net.floodlightcontroller.packet.UDP; //导入依赖的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.UDP; //导入依赖的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: createPacketIn
import net.floodlightcontroller.packet.UDP; //导入依赖的package包/类
private OFPacketIn createPacketIn(String srcMAC, String dstMAC,
String srcIp, String dstIp, short vlan) {
IPacket testPacket = new Ethernet()
.setDestinationMACAddress(dstMAC)
.setSourceMACAddress(srcMAC)
.setVlanID(vlan)
.setEtherType(EthType.IPv4)
.setPayload(
new IPv4()
.setTtl((byte) 128)
.setSourceAddress(srcIp)
.setDestinationAddress(dstIp)
.setPayload(new UDP()
.setSourcePort((short) 5000)
.setDestinationPort((short) 5001)
.setPayload(new Data(new byte[] {0x01}))));
byte[] testPacketSerialized = testPacket.serialize();
OFPacketIn pi;
// build out input packet
pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
.setBufferId(OFBufferId.NO_BUFFER)
.setData(testPacketSerialized)
.setReason(OFPacketInReason.NO_MATCH)
.build();
return pi;
}
示例4: snoopDHCPClientName
import net.floodlightcontroller.packet.UDP; //导入依赖的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());
}
}
}
示例5: createPacketIn
import net.floodlightcontroller.packet.UDP; //导入依赖的package包/类
private OFPacketIn createPacketIn(String srcMAC, String dstMAC,
String srcIp, String dstIp, short vlan) {
IPacket testPacket = new Ethernet()
.setDestinationMACAddress(dstMAC)
.setSourceMACAddress(srcMAC)
.setVlanID(vlan)
.setEtherType(Ethernet.TYPE_IPv4)
.setPayload(
new IPv4()
.setTtl((byte) 128)
.setSourceAddress(srcIp)
.setDestinationAddress(dstIp)
.setPayload(new UDP()
.setSourcePort((short) 5000)
.setDestinationPort((short) 5001)
.setPayload(new Data(new byte[] {0x01}))));
byte[] testPacketSerialized = testPacket.serialize();
OFPacketIn pi;
// build out input packet
pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
.setBufferId(OFBufferId.NO_BUFFER)
.setData(testPacketSerialized)
.setReason(OFPacketInReason.NO_MATCH)
.build();
return pi;
}
示例6: getSrcNwAddr
import net.floodlightcontroller.packet.UDP; //导入依赖的package包/类
/**
* Get IP address from packet if the packet is either an ARP
* or a DHCP packet
* @param eth
* @param dlAddr
* @return
*/
private int getSrcNwAddr(Ethernet eth, long dlAddr) {
if (eth.getPayload() instanceof ARP) {
ARP arp = (ARP) eth.getPayload();
if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) &&
(Ethernet.toLong(arp.getSenderHardwareAddress()) == dlAddr)) {
return IPv4.toIPv4Address(arp.getSenderProtocolAddress());
}
} else if (eth.getPayload() instanceof IPv4) {
IPv4 ipv4 = (IPv4) eth.getPayload();
if (ipv4.getPayload() instanceof UDP) {
UDP udp = (UDP)ipv4.getPayload();
if (udp.getPayload() instanceof DHCP) {
DHCP dhcp = (DHCP)udp.getPayload();
if (dhcp.getOpCode() == DHCP.OPCODE_REPLY) {
return ipv4.getSourceAddress();
}
}
}
}
return 0;
}
示例7: prepareOFPacketIn
import net.floodlightcontroller.packet.UDP; //导入依赖的package包/类
public static OFPacketIn prepareOFPacketIn(String destAddress) {
IPacket iPacket = new Ethernet()
.setDestinationMACAddress("00:11:22:33:44:55")
.setSourceMACAddress("00:44:33:22:11:00")
.setEtherType(Ethernet.TYPE_IPv4)
.setPayload(
new IPv4()
.setTtl((byte) 128)
.setSourceAddress("192.168.1.1")
.setDestinationAddress(destAddress)
.setPayload(new UDP()
.setSourcePort((short) 5000)
.setDestinationPort((short) 5001)
.setPayload(new Data(new byte[]{0x01}))));
byte[] iPacketSerialized = iPacket.serialize();
return new OFPacketIn()
.setBufferId(-1)
.setInPort((short) 1)
.setPacketData(iPacketSerialized)
.setReason(OFPacketIn.OFPacketInReason.NO_MATCH)
.setTotalLength((short) iPacketSerialized.length);
}
示例8: snoopDHCPClientName
import net.floodlightcontroller.packet.UDP; //导入依赖的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) {
srcDevice.dhcpClientName = new String(dhcpOption.getData());
}
}
}
示例9: snoopDHCPClientName
import net.floodlightcontroller.packet.UDP; //导入依赖的package包/类
/**
* Snoop and record client-provided host name from DHCP requests
* @param eth
* @param srcDevice
*/
private void snoopDHCPClientName(Ethernet eth, Device srcDevice) {
if (eth.getEtherType() != Ethernet.TYPE_IPv4)
return;
IPv4 ipv4 = (IPv4) eth.getPayload();
if (ipv4.getProtocol() != IPv4.PROTOCOL_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) {
srcDevice.dhcpClientName = new String(dhcpOption.getData());
}
}
}
示例10: getPacket
import net.floodlightcontroller.packet.UDP; //导入依赖的package包/类
protected IPacket getPacket() {
UDP udp = new UDP()
.setDestinationPort(
TransportPort.of(PathVerificationService.VERIFICATION_PACKET_UDP_PORT))
.setSourcePort(
TransportPort.of(PathVerificationService.VERIFICATION_PACKET_UDP_PORT));
VerificationPacket verificationPacket = new VerificationPacket()
.setChassisId(new LLDPTLV().setType((byte) 1).setLength((short) 7)
.setValue(new byte[] {0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}))
.setPortId(new LLDPTLV().setType((byte) 2).setLength((short) 3)
.setValue(new byte[] {0x02, 0x00, 0x01}))
.setTtl(new LLDPTLV().setType((byte) 3).setLength((short) 2)
.setValue(new byte[] {0x00, 0x78}));
udp.setPayload(new Data(verificationPacket.serialize()));
IPv4 ip = new IPv4()
.setSourceAddress("192.168.0.1")
.setDestinationAddress(PathVerificationService.VERIFICATION_PACKET_IP_DST)
.setProtocol(IpProtocol.UDP);
Ethernet eth = new Ethernet()
.setDestinationMACAddress("AA:BB:CC:DD:EE:FF")
.setSourceMACAddress("11:22:33:44:55:66")
.setEtherType(EthType.IPv4);
eth.setPayload(ip);
ip.setPayload(udp);
return eth;
}
示例11: isUDP
import net.floodlightcontroller.packet.UDP; //导入依赖的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;
}
}
示例12: getDstPort
import net.floodlightcontroller.packet.UDP; //导入依赖的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;
}
}
示例13: getSrcPort
import net.floodlightcontroller.packet.UDP; //导入依赖的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;
}
}
示例14: switchAdded
import net.floodlightcontroller.packet.UDP; //导入依赖的package包/类
@Override
public void switchAdded(DatapathId dpid) {
/* Insert static flows on all ports of the switch to redirect
* DHCP client --> DHCP DHCPServer traffic to the controller.
* DHCP client's operate on UDP port 67
*/
IOFSwitch sw = switchService.getSwitch(dpid);
//fix concurrency flaw
if (sw == null){
return;
}
OFFlowAdd.Builder flow = sw.getOFFactory().buildFlowAdd();
Match.Builder match = sw.getOFFactory().buildMatch();
ArrayList<OFAction> actionList = new ArrayList<OFAction>();
OFActionOutput.Builder action = sw.getOFFactory().actions().buildOutput();
for (OFPortDesc port : sw.getPorts()) {
match.setExact(MatchField.IN_PORT, port.getPortNo());
match.setExact(MatchField.ETH_TYPE, EthType.IPv4);
match.setExact(MatchField.IP_PROTO, IpProtocol.UDP);
match.setExact(MatchField.UDP_SRC, UDP.DHCP_CLIENT_PORT);
action.setMaxLen(0xffFFffFF);
action.setPort(OFPort.CONTROLLER);
actionList.add(action.build());
flow.setBufferId(OFBufferId.NO_BUFFER);
flow.setHardTimeout(0);
flow.setIdleTimeout(0);
flow.setOutPort(OFPort.CONTROLLER);
flow.setActions(actionList);
flow.setMatch(match.build());
flow.setPriority(32767);
sfp.addFlow("dhcp-port---" + port.getPortNo().getPortNumber() + "---(" + port.getName() + ")", flow.build(), sw.getId());
}
}