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


Java EtherTypes类代码示例

本文整理汇总了Java中org.opendaylight.controller.sal.utils.EtherTypes的典型用法代码示例。如果您正苦于以下问题:Java EtherTypes类的具体用法?Java EtherTypes怎么用?Java EtherTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EtherTypes类属于org.opendaylight.controller.sal.utils包,在下文中一共展示了EtherTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createEthernet

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
private static Ethernet createEthernet(byte[] sourceMAC, byte[] targetMAC, ARP arp, short vlan) {
    Ethernet ethernet = new Ethernet();
    ethernet.setSourceMACAddress(sourceMAC);
    ethernet.setDestinationMACAddress(targetMAC);
    if (vlan == 0) {
        ethernet.setEtherType(EtherTypes.ARP.shortValue());
        ethernet.setPayload(arp);
    } else {
        IEEE8021Q dot1q = new IEEE8021Q();
        dot1q.setVid(vlan);
        dot1q.setEtherType(EtherTypes.ARP.shortValue());
        dot1q.setPayload(arp);
        dot1q.setCfi((byte)0);
        dot1q.setPcp((byte)0);
        ethernet.setEtherType(EtherTypes.VLANTAGGED.shortValue());
        ethernet.setPayload(dot1q);
    }
    return ethernet;
}
 
开发者ID:imcmy,项目名称:ODLJumpIP,代码行数:20,代码来源:SimpleARP.java

示例2: installImplicitARPReplyPunt

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
private void installImplicitARPReplyPunt(Node node) {

        if (node == null) {
            return;
        }

        List<String> puntAction = new ArrayList<String>();
        puntAction.add(ActionType.CONTROLLER.toString());

        FlowConfig allowARP = new FlowConfig();
        allowARP.setInstallInHw(true);
        allowARP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt ARP Reply" + FlowConfig.INTERNALSTATICFLOWEND);
        allowARP.setPriority("500");
        allowARP.setNode(node);
        allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase());
        allowARP.setDstMac(HexEncode.bytesToHexString(switchManager.getControllerMAC()));
        allowARP.setActions(puntAction);
        addStaticFlowInternal(allowARP, true); // skip validation on internal static flow name
    }
 
开发者ID:lbchen,项目名称:ODL,代码行数:20,代码来源:ForwardingRulesManager.java

示例3: sendARPReply

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
protected void sendARPReply(NodeConnector p, byte[] sMAC, InetAddress sIP,
        byte[] tMAC, InetAddress tIP) {
    byte[] senderIP = sIP.getAddress();
    byte[] targetIP = tIP.getAddress();
    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET).setProtocolType(
            EtherTypes.IPv4.shortValue())
            .setHardwareAddressLength((byte) 6).setProtocolAddressLength(
                    (byte) 4).setOpCode(ARP.REPLY)
            .setSenderHardwareAddress(sMAC).setSenderProtocolAddress(
                    senderIP).setTargetHardwareAddress(tMAC)
            .setTargetProtocolAddress(targetIP);

    Ethernet ethernet = new Ethernet();
    ethernet.setSourceMACAddress(sMAC).setDestinationMACAddress(tMAC)
            .setEtherType(EtherTypes.ARP.shortValue()).setPayload(arp);

    RawPacket destPkt = this.dataPacketService.encodeDataPacket(ethernet);
    destPkt.setOutgoingNodeConnector(p);

    this.dataPacketService.transmitDataPacket(destPkt);
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:23,代码来源:ArpHandler.java

示例4: actionsAreIPv6

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
/**
 * Returns true if it finds at least one action which is for IPv6 in the
 * list of actions for this Flow
 *
 * @return
 */
private boolean actionsAreIPv6() {
    if (this.actions != null) {
        for (Action action : actions) {
            switch (action.getType()) {
            case SET_NW_SRC:
                if (((SetNwSrc) action).getAddress() instanceof Inet6Address) {
                    return true;
                }
                break;
            case SET_NW_DST:
                if (((SetNwDst) action).getAddress() instanceof Inet6Address) {
                    return true;
                }
                break;
            case SET_DL_TYPE:
                if (((SetDlType) action).getDlType() == EtherTypes.IPv6.intValue()) {
                    return true;
                }
                break;
            default:
            }
        }
    }
    return false;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:32,代码来源:Flow.java

示例5: testFlowActions

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
@Test
public void testFlowActions() throws UnknownHostException {
    Node node = NodeCreator.createOFNode(55l);
    Flow flow = getSampleFlowV6(node);

    List<Action> actions = flow.getActions();
    actions.add(new Loopback());

    Assert.assertTrue(flow.getActions() != actions);
    Assert.assertTrue(!flow.getActions().equals(actions));

    flow.addAction(new Loopback());
    Assert.assertTrue(flow.getActions().equals(actions));

    actions.remove(new Loopback());
    flow.removeAction(new Loopback());
    Assert.assertTrue(flow.getActions().equals(actions));

    // Add a malformed action
    Assert.assertFalse(flow.addAction(new PushVlan(EtherTypes.CISCOQINQ, 3,
            3, 8000)));
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:23,代码来源:FlowTest.java

示例6: setMatch

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
private Match setMatch(InetAddress srcIP, InetAddress destIP) {
    Match match = new Match();
    match.setField(
        new MatchField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue()));
    match.setField(
        new MatchField(MatchType.NW_SRC, srcIP));
    match.setField(
        new MatchField(MatchType.NW_DST, destIP));

    return match;
}
 
开发者ID:imcmy,项目名称:ODLJumpIP,代码行数:12,代码来源:JumpIP.java

示例7: createARP

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
private static ARP createARP(short opCode, byte[] senderMacAddress, byte[] senderIP, byte[] targetMacAddress,
        byte[] targetIP) {
    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
    arp.setProtocolType(EtherTypes.IPv4.shortValue());
    arp.setHardwareAddressLength((byte) 6);
    arp.setProtocolAddressLength((byte) 4);
    arp.setOpCode(opCode);
    arp.setSenderHardwareAddress(senderMacAddress);
    arp.setSenderProtocolAddress(senderIP);
    arp.setTargetHardwareAddress(targetMacAddress);
    arp.setTargetProtocolAddress(targetIP);
    return arp;
}
 
开发者ID:imcmy,项目名称:ODLJumpIP,代码行数:15,代码来源:SimpleARP.java

示例8: testFlowEntrySet

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
@Test
public void testFlowEntrySet() throws UnknownHostException {
    Set<FlowEntry> set = new HashSet<FlowEntry>();

    Node node1 = NodeCreator.createOFNode(1L);
    Node node2 = NodeCreator.createOFNode(2L);
    Node node3 = NodeCreator.createOFNode(3L);

    Match match = new Match();
    match.setField(MatchType.NW_SRC, InetAddress.getAllByName("1.1.1.1"));
    match.setField(MatchType.NW_DST, InetAddress.getAllByName("2.2.2.2"));
    match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue());

    List<Action> actionList = new ArrayList<Action>();
    // actionList.add(new Drop());

    Flow flow = new Flow(match, actionList);
    FlowEntry pol1 = new FlowEntry("m1", "same", flow, node1);
    FlowEntry pol2 = new FlowEntry("m2", "same", flow, node2);
    FlowEntry pol3 = new FlowEntry("m3", "same", flow, node3);

    set.add(pol1);
    set.add(pol2);
    set.add(pol3);

    Assert.assertTrue(set.contains(pol1));
    Assert.assertTrue(set.contains(pol2));
    Assert.assertTrue(set.contains(pol3));

    Assert.assertTrue(set.contains(pol1.clone()));
    Assert.assertTrue(set.contains(pol2.clone()));
    Assert.assertTrue(set.contains(pol3.clone()));

}
 
开发者ID:lbchen,项目名称:ODL,代码行数:35,代码来源:frmTest.java

示例9: sendUcastARPRequest

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
protected void sendUcastARPRequest(HostNodeConnector host, Subnet subnet) {
    //Long swID = host.getnodeconnectornodeId();
    //Short portID = host.getnodeconnectorportId();
    //Node n = NodeCreator.createOFNode(swID);
    Node n = host.getnodeconnectorNode();
    if (n == null) {
        logger.error("cannot send UcastARP because cannot extract node "
                + "from HostNodeConnector: {}", host);
        return;
    }
    NodeConnector outPort = host.getnodeConnector();
    if (outPort == null) {
        logger.error("cannot send UcastARP because cannot extract "
                + "outPort from HostNodeConnector: {}", host);
        return;
    }

    byte[] senderIP = subnet.getNetworkAddress().getAddress();
    byte[] targetIP = host.getNetworkAddress().getAddress();
    byte[] targetMAC = host.getDataLayerAddressBytes();
    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET).setProtocolType(
            EtherTypes.IPv4.shortValue())
            .setHardwareAddressLength((byte) 6).setProtocolAddressLength(
                    (byte) 4).setOpCode(ARP.REQUEST)
            .setSenderHardwareAddress(getControllerMAC())
            .setSenderProtocolAddress(senderIP).setTargetHardwareAddress(
                    targetMAC).setTargetProtocolAddress(targetIP);

    Ethernet ethernet = new Ethernet();
    ethernet.setSourceMACAddress(getControllerMAC())
            .setDestinationMACAddress(targetMAC).setEtherType(
                    EtherTypes.ARP.shortValue()).setPayload(arp);

    RawPacket destPkt = this.dataPacketService.encodeDataPacket(ethernet);
    destPkt.setOutgoingNodeConnector(outPort);

    this.dataPacketService.transmitDataPacket(destPkt);
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:40,代码来源:ArpHandler.java

示例10: isIPv6

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
/**
 * Returns whether this match is for an IPv6 flow
 */
public boolean isIPv6() {
    return (isPresent(MatchType.DL_TYPE)
            && ((Short) getField(MatchType.DL_TYPE).getValue())
                    .equals(EtherTypes.IPv6.shortValue())
            || isPresent(MatchType.NW_PROTO)
            && ((Byte) getField(MatchType.NW_PROTO).getValue())
                    .equals(IPProtocols.IPV6ICMP.byteValue())
            || isPresent(MatchType.NW_SRC)
            && getField(MatchType.NW_SRC).getValue() instanceof Inet6Address || isPresent(MatchType.NW_DST)
            && getField(MatchType.NW_DST).getValue() instanceof Inet6Address);
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:15,代码来源:Match.java

示例11: PushVlan

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
public PushVlan(EtherTypes tag, int pcp, int cfi, int vlanId) {
    type = ActionType.PUSH_VLAN;
    this.tag = tag.intValue();
    this.cfi = cfi;
    this.pcp = pcp;
    this.vlanId = vlanId;
    this.tci = createTci();
    this.header = createHeader();
    runChecks();
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:11,代码来源:PushVlan.java

示例12: runChecks

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
private void runChecks() {
    checkValue(ActionType.SET_DL_TYPE, tag);
    checkValue(ActionType.SET_VLAN_PCP, pcp);
    checkValue(ActionType.SET_VLAN_CFI, cfi);
    checkValue(ActionType.SET_VLAN_ID, vlanId);
    checkValue(tci);

    // Run action specific check which cannot be run by parent
    if (tag != EtherTypes.VLANTAGGED.intValue() && tag != EtherTypes.QINQ.intValue()
            && tag != EtherTypes.OLDQINQ.intValue() && tag != EtherTypes.CISCOQINQ.intValue()) {
        // pass a value which will tell fail and tell something about the
        // original wrong value
        checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
    }
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:16,代码来源:PushVlan.java

示例13: testMatchSetGetEtherType

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
@Test
public void testMatchSetGetEtherType() throws UnknownHostException {
    Match x = new Match();

    x.setField(MatchType.DL_TYPE, EtherTypes.QINQ.shortValue(), (short) 0xffff);
    Assert.assertTrue(((Short) x.getField(MatchType.DL_TYPE).getValue()).equals(EtherTypes.QINQ.shortValue()));
    Assert.assertFalse(x.getField(MatchType.DL_TYPE).getValue() == EtherTypes.QINQ);
    Assert.assertFalse(x.getField(MatchType.DL_TYPE).getValue().equals(EtherTypes.QINQ));

    x.setField(MatchType.DL_TYPE, EtherTypes.LLDP.shortValue(), (short) 0xffff);
    Assert.assertTrue(((Short) x.getField(MatchType.DL_TYPE).getValue()).equals(EtherTypes.LLDP.shortValue()));
    Assert.assertFalse(x.getField(MatchType.DL_TYPE).equals(EtherTypes.LLDP.intValue()));
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:14,代码来源:MatchTest.java

示例14: testFlowOnNodeMethods

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
@Test
        public void testFlowOnNodeMethods () {
        Match match = new Match();
        NodeConnector inNC = NodeConnectorCreator.createNodeConnector((short)10, NodeCreator.createOFNode((long)10));
        NodeConnector outNC = NodeConnectorCreator.createNodeConnector((short)20, NodeCreator.createOFNode((long)20));

        match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue());
        match.setField(MatchType.IN_PORT, inNC);

        Output output = new Output(outNC);
        ArrayList<Action> action = new ArrayList<Action>();
        action.add(output);

        Flow flow = new Flow (match, action);

        FlowOnNode flowOnNode = new FlowOnNode (flow);

        Assert.assertTrue(flowOnNode.getFlow().equals(flow));

        flowOnNode.setPacketCount((long)100);
        flowOnNode.setByteCount((long)800);
        flowOnNode.setTableId((byte)0x55);
        flowOnNode.setDurationNanoseconds(40);
        flowOnNode.setDurationSeconds(45);

        Assert.assertTrue(flowOnNode.getPacketCount() == 100);
        Assert.assertTrue(flowOnNode.getByteCount() == 800);
        Assert.assertTrue(flowOnNode.getDurationNanoseconds() == 40);
        Assert.assertTrue(flowOnNode.getDurationSeconds() == 45);
        Assert.assertTrue(flowOnNode.getTableId() == (byte)0x55);
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:32,代码来源:FlowOnNodeTest.java

示例15: getSampleFlowV6

import org.opendaylight.controller.sal.utils.EtherTypes; //导入依赖的package包/类
private Flow getSampleFlowV6(Node node) throws UnknownHostException {
    NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
    NodeConnector oport = NodeConnectorCreator.createOFNodeConnector((short) 30, node);
    byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
    byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
    byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34, (byte) 0x9a, (byte) 0xee };
    InetAddress srcIP = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
    InetAddress dstIP = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
    InetAddress ipMask = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
    InetAddress ipMask2 = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
    InetAddress newIP = InetAddress.getByName("2056:650::a1b0");
    short ethertype = EtherTypes.IPv6.shortValue();
    short vlan = (short) 27;
    byte vlanPr = (byte) 3;
    Byte tos = 4;
    byte proto = IPProtocols.UDP.byteValue();
    short src = (short) 5500;
    short dst = 80;

    /*
     * Create a SAL Flow aFlow
     */
    Match match = new Match();
    match.setField(MatchType.IN_PORT, port);
    match.setField(MatchType.DL_SRC, srcMac);
    match.setField(MatchType.DL_DST, dstMac);
    match.setField(MatchType.DL_TYPE, ethertype);
    match.setField(MatchType.DL_VLAN, vlan);
    match.setField(MatchType.DL_VLAN_PR, vlanPr);
    match.setField(MatchType.NW_SRC, srcIP, ipMask);
    match.setField(MatchType.NW_DST, dstIP, ipMask2);
    match.setField(MatchType.NW_TOS, tos);
    match.setField(MatchType.NW_PROTO, proto);
    match.setField(MatchType.TP_SRC, src);
    match.setField(MatchType.TP_DST, dst);

    List<Action> actions = new ArrayList<Action>();
    actions.add(new Controller());
    actions.add(new SetVlanId(5));
    actions.add(new SetDlDst(newMac));
    actions.add(new SetNwDst(newIP));
    actions.add(new Output(oport));
    actions.add(new PopVlan());
    actions.add(new Flood());

    Flow flow = new Flow(match, actions);
    flow.setPriority((short) 300);
    flow.setHardTimeout((short) 240);

    return flow;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:52,代码来源:frmTest.java


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