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


Java PacketContext类代码示例

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


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

示例1: process

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void process(PacketContext context) {
    if (context == null || context.isHandled()) {
        return;
    }

    Ethernet eth = context.inPacket().parsed();
    if (eth == null || (eth.getEtherType() != TYPE_LLDP && eth.getEtherType() != TYPE_BSN)) {
        return;
    }

    LinkDiscovery ld = discoverers.get(context.inPacket().receivedFrom().deviceId());
    if (ld == null) {
        return;
    }

    if (ld.handleLldp(context)) {
        context.block();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:LldpLinkProvider.java

示例2: extractLinkKey

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
LinkKey extractLinkKey(PacketContext packetContext) {
    Ethernet eth = packetContext.inPacket().parsed();
    if (eth == null) {
        return null;
    }

    ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
    if (onoslldp != null) {
        PortNumber srcPort = portNumber(onoslldp.getPort());
        PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
        DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
        DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();

        ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
        ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
        return LinkKey.linkKey(src, dst);
    }
    return null;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:NetworkConfigLinksProvider.java

示例3: testNotConfiguredLink

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
/**
 * Tests discovery of a link that is not expected in the configuration.
 */
@Test
public void testNotConfiguredLink() {
    PacketContext pktCtx = new TestPacketContext(src, dst);

    testProcessor.process(pktCtx);

    assertThat(providerService.discoveredLinks().entrySet(), hasSize(1));
    DeviceId destination = providerService.discoveredLinks().get(dev1.id());
    assertThat(destination, notNullValue());
    LinkKey key = LinkKey.linkKey(src, dst);
    LinkDescription linkDescription = providerService
            .discoveredLinkDescriptions().get(key);
    assertThat(linkDescription, notNullValue());
    assertThat(linkDescription.isExpected(), is(false));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:NetworkConfigLinksProviderTest.java

示例4: testConfiguredLink

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
/**
 * Tests discovery of an expected link.
 */
@Test
public void testConfiguredLink() {
    LinkKey key = LinkKey.linkKey(src, dst);
    configListener.event(new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED,
                                                key,
                                                BasicLinkConfig.class));

    PacketContext pktCtx = new TestPacketContext(src, dst);

    testProcessor.process(pktCtx);

    assertThat(providerService.discoveredLinks().entrySet(), hasSize(1));
    DeviceId destination = providerService.discoveredLinks().get(dev1.id());
    assertThat(destination, notNullValue());
    LinkDescription linkDescription = providerService
            .discoveredLinkDescriptions().get(key);
    assertThat(linkDescription, notNullValue());
    assertThat(linkDescription.isExpected(), is(true));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:NetworkConfigLinksProviderTest.java

示例5: handlePacketIn

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void handlePacketIn(Bmv2Device device, int inputPort, ImmutableByteSequence packet) {
    Ethernet ethPkt = new Ethernet();
    ethPkt.deserialize(packet.asArray(), 0, packet.size());

    DeviceId deviceId = device.asDeviceId();
    ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(inputPort));

    ByteBuffer rawData = ByteBuffer.wrap(packet.asArray());

    InboundPacket inPkt = new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
    OutboundPacket outPkt = new DefaultOutboundPacket(deviceId, null, rawData);

    PacketContext pktCtx = new Bmv2PacketContext(System.currentTimeMillis(), inPkt, outPkt, false);

    providerService.processPacket(pktCtx);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:Bmv2PacketProvider.java

示例6: forwardPacketToDst

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
/**
 * Forward the packet to it's multicast destinations.
 *
 * @param context The packet context
 * @param egressList The list of egress ports which the multicast packet is intended for.
 */
private void forwardPacketToDst(PacketContext context, ArrayList<ConnectPoint> egressList) {

    // Send the pack out each of the respective egress ports
    for (ConnectPoint egress : egressList) {
        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                .setOutput(egress.port()).build();

        OutboundPacket packet = new DefaultOutboundPacket(
                egress.deviceId(),
                treatment,
                context.inPacket().unparsed());

        packetService.emit(packet);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:McastForwarding.java

示例7: process

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void process(PacketContext context) {
    // Stop processing if the packet has been handled, since we
    // can't do any more to it.
    if (context.isHandled()) {
        return;
    }

    Ethernet packet = context.inPacket().parsed();

    if (packet == null) {
        return;
    }

    if (packet.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) packet.getPayload();
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_TCP) {
            TCP tcpPacket = (TCP) ipv4Packet.getPayload();

            if (tcpPacket.getDestinationPort() == BGP_PORT ||
                    tcpPacket.getSourcePort() == BGP_PORT) {
                forward(context);
            }
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:TunnellingConnectivityManager.java

示例8: process

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void process(PacketContext context) {
    // Stop processing if the packet has been handled, since we
    // can't do any more to it.

    if (context.isHandled()) {
        return;
    }

    Ethernet packet = context.inPacket().parsed();

    if (packet == null) {
        return;
    }

    if (packet.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) packet.getPayload();
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            processPacketIn(context.inPacket());
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:IcmpHandler.java

示例9: processArpPacket

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
/**
 * Processes the ARP Payload and initiates a reply to the client.
 *
 * @param context context of the incoming message
 * @param packet the ethernet payload
 */
private void processArpPacket(PacketContext context, Ethernet packet) {

    ARP arpPacket = (ARP) packet.getPayload();

    ARP arpReply = (ARP) arpPacket.clone();
    arpReply.setOpCode(ARP.OP_REPLY);

    arpReply.setTargetProtocolAddress(arpPacket.getSenderProtocolAddress());
    arpReply.setTargetHardwareAddress(arpPacket.getSenderHardwareAddress());
    arpReply.setSenderProtocolAddress(arpPacket.getTargetProtocolAddress());
    arpReply.setSenderHardwareAddress(myMAC.toBytes());

    // Ethernet Frame.
    Ethernet ethReply = new Ethernet();
    ethReply.setSourceMACAddress(myMAC);
    ethReply.setDestinationMACAddress(packet.getSourceMAC());
    ethReply.setEtherType(Ethernet.TYPE_ARP);
    ethReply.setVlanID(packet.getVlanID());

    ethReply.setPayload(arpReply);
    sendReply(context, ethReply);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:29,代码来源:DhcpManager.java

示例10: discoverHost

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
/**
 * Integrates hosts learned through DHCP into topology.
 * @param context context of the incoming message
 * @param ipAssigned IP Address assigned to the host by DHCP Manager
 */
private void discoverHost(PacketContext context, Ip4Address ipAssigned) {
    if (!allowHostDiscovery) {
        // host discovery is not allowed, do nothing
        return;
    }

    Ethernet packet = context.inPacket().parsed();
    MacAddress mac = packet.getSourceMAC();
    VlanId vlanId = VlanId.vlanId(packet.getVlanID());
    HostLocation hostLocation = new HostLocation(context.inPacket().receivedFrom(), 0);

    Set<IpAddress> ips = new HashSet<>();
    ips.add(ipAssigned);

    HostId hostId = HostId.hostId(mac, vlanId);
    DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, hostLocation, ips);

    log.info("Discovered host {}", desc);
    hostProviderService.hostDetected(hostId, desc, false);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:DhcpManager.java

示例11: process

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void process(PacketContext context) {

    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    log.trace("Rcvd pktin: {}", ethernet);
    if (ethernet.getEtherType() == Ethernet.TYPE_ARP) {
        arpHandler.processPacketIn(pkt);
    } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipPacket = (IPv4) ethernet.getPayload();
        ipHandler.addToPacketBuffer(ipPacket);
        if (ipPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
            icmpHandler.processPacketIn(pkt);
        } else {
            ipHandler.processPacketIn(pkt);
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:SegmentRoutingManager.java

示例12: process

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    Ethernet ethPacket = context.inPacket().parsed();
    if (ethPacket == null || ethPacket.getEtherType() != Ethernet.TYPE_IPV4) {
        return;
    }
    IPv4 ipv4Packet = (IPv4) ethPacket.getPayload();
    if (ipv4Packet.getProtocol() != IPv4.PROTOCOL_UDP) {
        return;
    }
    UDP udpPacket = (UDP) ipv4Packet.getPayload();
    if (udpPacket.getDestinationPort() != UDP.DHCP_SERVER_PORT ||
            udpPacket.getSourcePort() != UDP.DHCP_CLIENT_PORT) {
        return;
    }

    DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
    processDhcp(context, dhcpPacket);
}
 
开发者ID:opencord,项目名称:vtn,代码行数:24,代码来源:CordVtnDhcpProxy.java

示例13: sendReply

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
private void sendReply(PacketContext context, Ethernet ethReply) {
    if (ethReply == null) {
        return;
    }
    ConnectPoint srcPoint = context.inPacket().receivedFrom();
    TrafficTreatment treatment = DefaultTrafficTreatment
            .builder()
            .setOutput(srcPoint.port())
            .build();

    packetService.emit(new DefaultOutboundPacket(
            srcPoint.deviceId(),
            treatment,
            ByteBuffer.wrap(ethReply.serialize())));
    context.block();
}
 
开发者ID:opencord,项目名称:vtn,代码行数:17,代码来源:CordVtnDhcpProxy.java

示例14: process

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }
    Ethernet ethPacket = context.inPacket().parsed();
    if (ethPacket == null || ethPacket.getEtherType() != Ethernet.TYPE_ARP) {
        return;
    }

    ARP arpPacket = (ARP) ethPacket.getPayload();
    switch (arpPacket.getOpCode()) {
        case ARP.OP_REQUEST:
            processArpRequest(context, ethPacket);
            break;
        case ARP.OP_REPLY:
            processArpReply(context, ethPacket);
            break;
        default:
            break;
    }
}
 
开发者ID:opencord,项目名称:vtn,代码行数:23,代码来源:CordVtnArpProxy.java

示例15: process

import org.onosproject.net.packet.PacketContext; //导入依赖的package包/类
@Override
public void process(PacketContext context) {
	if (context.isHandled()) {
		return;
	}
	InboundPacket pkt = context.inPacket();
	Ethernet ethPkt = pkt.parsed();

	if (ethPkt == null) {
		return;
	}

	if (ethPkt.getEtherType() == EtherType.ARP.ethType().toShort()) {
		context.treatmentBuilder().setOutput(PortNumber.FLOOD);
		context.send();
	}
}
 
开发者ID:ShakhMoves,项目名称:ShakhSDVPN,代码行数:18,代码来源:ARPHandler.java


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