本文整理汇总了Java中net.floodlightcontroller.packet.Ethernet.TYPE_IPv4方法的典型用法代码示例。如果您正苦于以下问题:Java Ethernet.TYPE_IPv4方法的具体用法?Java Ethernet.TYPE_IPv4怎么用?Java Ethernet.TYPE_IPv4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.packet.Ethernet
的用法示例。
在下文中一共展示了Ethernet.TYPE_IPv4方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimpleAllowRule
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
@Test
public void testSimpleAllowRule() throws Exception {
// enable firewall first
firewall.enableFirewall(true);
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.dl_type = Ethernet.TYPE_IPv4;
rule.wildcard_dl_type = false;
rule.nw_proto = IPv4.PROTOCOL_TCP;
rule.wildcard_nw_proto = false;
// source is IP 192.168.1.2
rule.nw_src_prefix = IPv4.toIPv4Address("192.168.1.2");
rule.wildcard_nw_src = false;
// dest is network 192.168.1.0/24
rule.nw_dst_prefix = IPv4.toIPv4Address("192.168.1.0");
rule.nw_dst_maskbits = 24;
rule.wildcard_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(decision.getRoutingAction(), IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD);
// 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(decision.getRoutingAction(), IRoutingDecision.RoutingAction.DROP);
}
示例2: testOverlappingRules
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的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 = Ethernet.TYPE_IPv4;
rule.wildcard_dl_type = false;
rule.nw_proto = IPv4.PROTOCOL_TCP;
rule.wildcard_nw_proto = false;
rule.tp_dst = 80;
rule.priority = 1;
firewall.addRule(rule);
// add block all rule
rule = new FirewallRule();
rule.action = FirewallRule.FirewallAction.DENY;
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);
}