Search in sources :

Example 21 with DhcpServerInfo

use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.

the class Dhcp6HandlerImpl method processDhcp6ForwardOnly.

private List<InternalPacket> processDhcp6ForwardOnly(PacketContext context, Ethernet clientPacket, Set<Interface> clientInterfaces, DHCP6 dhcpPacket) {
    ConnectPoint inPort = context.inPacket().receivedFrom();
    log.trace("Got DHCPv6 on port {}", inPort);
    boolean directConnFlag = Dhcp6HandlerUtil.directlyConnected(dhcpPacket);
    List<InternalPacket> internalPackets = new ArrayList<>();
    List<DhcpServerInfo> serverInfoList = findValidServerInfo(directConnFlag);
    for (DhcpServerInfo dhcpServer : serverInfoList) {
        Interface serverInterface = getServerInterface(dhcpServer);
        if (serverInterface == null) {
            log.warn("Can't get server interface, ignore");
            continue;
        }
        Ethernet newPacket = Dhcp6HandlerUtil.buildDhcp6PacketFromClient(context, clientPacket, clientInterfaces, dhcpServer, serverInterface);
        log.trace("Built packet for server {} : {}", dhcpServer, newPacket);
        internalPackets.add(InternalPacket.internalPacket(newPacket, dhcpServer.getDhcpServerConnectPoint().get()));
    }
    return internalPackets;
}
Also used : Ethernet(org.onlab.packet.Ethernet) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) Interface(org.onosproject.net.intf.Interface)

Example 22 with DhcpServerInfo

use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.

the class DhcpRelayCommand method doExecute.

@Override
protected void doExecute() {
    List<DhcpServerInfo> defaultDhcpServerInfoList = DHCP_RELAY_SERVICE.getDefaultDhcpServerInfoList();
    List<DhcpServerInfo> indirectDhcpServerInfoList = DHCP_RELAY_SERVICE.getIndirectDhcpServerInfoList();
    if (defaultDhcpServerInfoList.isEmpty() && indirectDhcpServerInfoList.isEmpty()) {
        print(MISSING_SERVER_CFG);
        return;
    }
    if (!defaultDhcpServerInfoList.isEmpty()) {
        print(DEFAULT_SERVERS);
        listServers(defaultDhcpServerInfoList);
    }
    if (!indirectDhcpServerInfoList.isEmpty()) {
        print(INDIRECT_SERVERS);
        listServers(indirectDhcpServerInfoList);
    }
    // DHCP records
    Collection<DhcpRecord> records = DHCP_RELAY_SERVICE.getDhcpRecords();
    if (records.isEmpty()) {
        print(NO_RECORDS);
        return;
    }
    // Handle display of counters
    boolean toResetFlag;
    if (counter != null) {
        if (counter.equals("counter") || counter.equals("[counter]")) {
            print(CONUTER_HEADER);
        } else {
            print("first parameter is [counter]");
            return;
        }
        if (reset != null) {
            if (reset.equals("reset") || reset.equals("[reset]")) {
                toResetFlag = true;
            } else {
                print("Last parameter is [reset]");
                return;
            }
        } else {
            toResetFlag = false;
        }
        records.forEach(record -> {
            print(COUNTER_HOST, record.macAddress(), record.vlanId(), record.locations(), record.directlyConnected() ? DIRECTLY : EMPTY);
            DhcpRelayCounters v6Counters = record.getV6Counters();
            Map<String, Integer> countersMap = v6Counters.getCounters();
            countersMap.forEach((name, value) -> {
                print("%-30s  ............................  %-4d packets", name, value);
            });
            if (toResetFlag) {
                v6Counters.resetCounters();
                record.updateLastSeen();
                DHCP_RELAY_SERVICE.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
            }
        });
        return;
    }
    // Handle display of records
    print(HEADER);
    records.forEach(record -> print(HOST, record.macAddress(), record.vlanId(), record.locations(), record.directlyConnected() ? DIRECTLY : EMPTY, Tools.timeAgo(record.lastSeen()), ip4State(record), ip6State(record)));
}
Also used : DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Aggregations

DhcpServerInfo (org.onosproject.dhcprelay.api.DhcpServerInfo)22 ConnectPoint (org.onosproject.net.ConnectPoint)16 Ethernet (org.onlab.packet.Ethernet)14 VlanId (org.onlab.packet.VlanId)14 Interface (org.onosproject.net.intf.Interface)14 ArrayList (java.util.ArrayList)13 MacAddress (org.onlab.packet.MacAddress)13 UDP (org.onlab.packet.UDP)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)12 IpAddress (org.onlab.packet.IpAddress)12 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)12 List (java.util.List)11 DeviceId (org.onosproject.net.DeviceId)11 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)10 Collection (java.util.Collection)10 Optional (java.util.Optional)10 Set (java.util.Set)10 BasePacket (org.onlab.packet.BasePacket)10 Tools (org.onlab.util.Tools)10 Preconditions.checkState (com.google.common.base.Preconditions.checkState)9