Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2015 Open Networking Laboratory
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.onosproject.virtualbng;
 import static org.slf4j.LoggerFactory.getLogger;
When the upstream gateway which is outside local SDN network wants to send packets to our local public IP addresses, it will send out ARP requests to get the MAC address of each public IP address. Actually, there are no hosts configured with those public IP addresses, so this class is to emulate the behavior of the non-existed hosts and return ARP replies.

Since we will rewrite the destination MAC address in the switch before traffic packets go to the destination, so the MAC address can be any number. We manually configured a random MAC address for this purpose in the vBNG configuration file.

 @Component(immediate = true)
 public class VirtualPublicHosts {
     private final Logger log = getLogger(getClass());
     private static final String APP_NAME =
     protected CoreService coreService;
     protected PacketService packetService;
     private ApplicationId appId;
     private ArpRequestProcessor processor = new ArpRequestProcessor();
     public void activate() {
                                    . + 6);
         TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
         // Only IPv4 is supported in current vBNG.
         .info("vBNG virtual public hosts started");
     public void deactivate() {
          = null;
         .info("vBNG virtual public hosts Stopped");

This class filters out the ARP request packets, generates the ARP reply packets, and emits those packets.
    private class ArpRequestProcessor implements PacketProcessor {
        public void process(PacketContext context) {
            InboundPacket pkt = context.inPacket();
            Ethernet ethPkt = pkt.parsed();
            // Only handle the ARP packets
            if (ethPkt == null || ethPkt.getEtherType() != .) {
            ARP arpPacket = (ARPethPkt.getPayload();
            // Only handle ARP request packets
            if (arpPacket.getOpCode() != .) {
            Ip4Address targetIpAddress = Ip4Address
            // Only handle an ARP request when the target IP address inside is
            // an assigned public IP address
            if (!.isAssignedPublicIpAddress(targetIpAddress)) {
            MacAddress virtualHostMac =
            if (virtualHostMac == null) {
            ConnectPoint srcConnectPoint = pkt.receivedFrom();
            Ethernet eth = ARP.buildArpReply(targetIpAddress,
            TrafficTreatment.Builder builder =
            .emit(new DefaultOutboundPacket(
New to GrepCode? Check out our FAQ X