当前位置: 首页>>代码示例>>Java>>正文


Java Ethernet.TYPE_IPv4方法代码示例

本文整理汇总了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);
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:41,代码来源:FirewallTest.java

示例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);
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:44,代码来源:FirewallTest.java


注:本文中的net.floodlightcontroller.packet.Ethernet.TYPE_IPv4方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。