本文整理汇总了Java中net.floodlightcontroller.packet.TCP类的典型用法代码示例。如果您正苦于以下问题:Java TCP类的具体用法?Java TCP怎么用?Java TCP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TCP类属于net.floodlightcontroller.packet包,在下文中一共展示了TCP类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRuleDeletion
import net.floodlightcontroller.packet.TCP; //导入依赖的package包/类
@Test
public void testRuleDeletion() throws Exception {
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 1;
firewall.addRule(rule);
int rid = rule.ruleid;
List<Map<String, Object>> rulesFromStorage = firewall.getStorageRules();
assertEquals(1, rulesFromStorage.size());
assertEquals(Integer.parseInt((String)rulesFromStorage.get(0).get("ruleid")), rid);
// delete rule
firewall.deleteRule(rid);
rulesFromStorage = firewall.getStorageRules();
assertEquals(0, rulesFromStorage.size());
}
示例2: testFirewallDisabled
import net.floodlightcontroller.packet.TCP; //导入依赖的package包/类
@Test
public void testFirewallDisabled() throws Exception {
// firewall isn't enabled by default
// so, it shouldn't make any decision
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 1;
firewall.addRule(rule);
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
assertEquals(1, firewall.rules.size());
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertNull(decision);
}
示例3: isTCP
import net.floodlightcontroller.packet.TCP; //导入依赖的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;
}
}
示例4: getDstPort
import net.floodlightcontroller.packet.TCP; //导入依赖的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.TCP; //导入依赖的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: testReadRulesFromStorage
import net.floodlightcontroller.packet.TCP; //导入依赖的package包/类
@Test
public void testReadRulesFromStorage() throws Exception {
// add 2 rules first
FirewallRule rule = new FirewallRule();
rule.in_port = OFPort.of(2);
rule.dl_src = MacAddress.of("00:00:00:00:00:01");
rule.dl_dst = MacAddress.of("00:00:00:00:00:02");
rule.priority = 1;
rule.action = FirewallRule.FirewallAction.DROP;
firewall.addRule(rule);
rule = new FirewallRule();
rule.in_port = OFPort.of(3);
rule.dl_src = MacAddress.of("00:00:00:00:00:02");
rule.dl_dst = MacAddress.of("00:00:00:00:00:01");
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.tp_dst = TransportPort.of(80);
rule.priority = 2;
rule.action = FirewallRule.FirewallAction.ALLOW;
firewall.addRule(rule);
List<FirewallRule> rules = firewall.readRulesFromStorage();
// verify rule 1
FirewallRule r = rules.get(0);
assertEquals(r.in_port, OFPort.of(2));
assertEquals(r.priority, 1);
assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:01"));
assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:02"));
assertEquals(r.action, FirewallRule.FirewallAction.DROP);
// verify rule 2
r = rules.get(1);
assertEquals(r.in_port, OFPort.of(3));
assertEquals(r.priority, 2);
assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:02"));
assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:01"));
assertEquals(r.nw_proto, IpProtocol.TCP);
assertEquals(r.tp_dst, TransportPort.of(80));
assertEquals(r.any_nw_proto, false);
assertEquals(r.action, FirewallRule.FirewallAction.ALLOW);
}
示例7: testRuleInsertionIntoStorage
import net.floodlightcontroller.packet.TCP; //导入依赖的package包/类
@Test
public void testRuleInsertionIntoStorage() throws Exception {
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 1;
firewall.addRule(rule);
List<Map<String, Object>> rulesFromStorage = firewall.getStorageRules();
assertEquals(1, rulesFromStorage.size());
assertEquals(Integer.parseInt((String)rulesFromStorage.get(0).get("ruleid")), rule.ruleid);
}
示例8: testSimpleAllowRule
import net.floodlightcontroller.packet.TCP; //导入依赖的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());
}
示例9: testLayer2Rule
import net.floodlightcontroller.packet.TCP; //导入依赖的package包/类
@Test
public void testLayer2Rule() throws Exception {
// enable firewall first
firewall.enableFirewall(true);
// add L2 rule
FirewallRule rule = new FirewallRule();
rule.dl_src = MacAddress.of("00:44:33:22:11:00");
rule.any_dl_src = false;
rule.dl_dst = MacAddress.of("00:11:22:33:44:55");
rule.any_dl_dst = false;
rule.priority = 1;
firewall.addRule(rule);
// add TCP deny all rule
rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 2;
rule.action = FirewallRule.FirewallAction.DROP;
firewall.addRule(rule);
// simulate a packet-in event
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);
}
示例10: getUnicityDiff
import net.floodlightcontroller.packet.TCP; //导入依赖的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);
}