Marc De Leenheer
Committed by Gerrit Code Review

Inject and remove static routes.

Change-Id: I8be1414978fd0b5dfb7186aeb86d100087502748
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.routing;
17 +
18 +/**
19 + * Convenience interface to obtain the FIB listener.
20 + */
21 +public interface StaticRoutingService {
22 +
23 + FibListener getFibListener();
24 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.routing.cli;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onlab.packet.IpAddress;
21 +import org.onlab.packet.IpPrefix;
22 +import org.onlab.packet.MacAddress;
23 +import org.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.routing.FibEntry;
25 +import org.onosproject.routing.FibListener;
26 +import org.onosproject.routing.FibUpdate;
27 +import org.onosproject.routing.StaticRoutingService;
28 +
29 +import java.util.Arrays;
30 +import java.util.Collections;
31 +
32 +@Command(scope = "onos", name = "add-route", description = "Installs static route")
33 +public class AddRouteCommand extends AbstractShellCommand {
34 +
35 + @Argument(index = 0, name = "prefix IP MAC",
36 + description = "prefix nexthopIP nexthopMAC",
37 + required = true, multiValued = true)
38 + String[] fibEntryString = null;
39 +
40 + @Override
41 + protected void execute() {
42 + StaticRoutingService routingService = get(StaticRoutingService.class);
43 +
44 + if (fibEntryString.length < 3) {
45 + return;
46 + }
47 +
48 + IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]);
49 + IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]);
50 + MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]);
51 + FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac);
52 + FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
53 +
54 + FibListener fibListener = routingService.getFibListener();
55 + fibListener.update(Arrays.asList(fibUpdate), Collections.emptyList());
56 + }
57 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.routing.cli;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onlab.packet.IpAddress;
21 +import org.onlab.packet.IpPrefix;
22 +import org.onlab.packet.MacAddress;
23 +import org.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.routing.FibEntry;
25 +import org.onosproject.routing.FibListener;
26 +import org.onosproject.routing.FibUpdate;
27 +import org.onosproject.routing.StaticRoutingService;
28 +
29 +import java.util.Arrays;
30 +import java.util.Collections;
31 +
32 +@Command(scope = "onos", name = "remove-route", description = "Removes static route")
33 +public class RemoveRouteCommand extends AbstractShellCommand {
34 + @Argument(index = 0, name = "prefix IP MAC",
35 + description = "prefix nexthopIP nexthopMAC",
36 + required = true, multiValued = true)
37 + String[] fibEntryString = null;
38 +
39 + @Override
40 + protected void execute() {
41 + StaticRoutingService routingService = get(StaticRoutingService.class);
42 +
43 + if (fibEntryString.length < 3) {
44 + return;
45 + }
46 +
47 + IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]);
48 + IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]);
49 + MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]);
50 + FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac);
51 + FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry);
52 +
53 + FibListener fibListener = routingService.getFibListener();
54 + fibListener.update(Collections.emptyList(), Arrays.asList(fibUpdate));
55 + }
56 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.routing.impl;
17 +
18 +import org.apache.felix.scr.annotations.Component;
19 +import org.apache.felix.scr.annotations.Service;
20 +import org.onlab.packet.IpAddress;
21 +import org.onlab.packet.MacAddress;
22 +import org.onosproject.net.ConnectPoint;
23 +import org.onosproject.routing.FibListener;
24 +import org.onosproject.routing.IntentRequestListener;
25 +import org.onosproject.routing.RouteEntry;
26 +import org.onosproject.routing.RoutingService;
27 +import org.onosproject.routing.StaticRoutingService;
28 +
29 +import java.util.Collection;
30 +
31 +/**
32 + * Static router maintains handle to FIB listener.
33 + *
34 + * TODO: implement getRoutes methods
35 + */
36 +@Component(immediate = true, enabled = false)
37 +@Service
38 +public class StaticRouter implements RoutingService, StaticRoutingService {
39 + private FibListener fibListener;
40 +
41 + @Override
42 + public void start() {
43 +
44 + }
45 +
46 + @Override
47 + public void addFibListener(FibListener fibListener) {
48 + this.fibListener = fibListener;
49 + }
50 +
51 + @Override
52 + public void addIntentRequestListener(IntentRequestListener intentRequestListener) {
53 +
54 + }
55 +
56 + @Override
57 + public void stop() {
58 +
59 + }
60 +
61 + @Override
62 + public Collection<RouteEntry> getRoutes4() {
63 + return null;
64 + }
65 +
66 + @Override
67 + public Collection<RouteEntry> getRoutes6() {
68 + return null;
69 + }
70 +
71 + @Override
72 + public LocationType getLocationType(IpAddress ipAddress) {
73 + return null;
74 + }
75 +
76 + @Override
77 + public RouteEntry getLongestMatchableRouteEntry(IpAddress ipAddress) {
78 + return null;
79 + }
80 +
81 + @Override
82 + public ConnectPoint getEgressConnectPoint(IpAddress dstIpAddress) {
83 + return null;
84 + }
85 +
86 + @Override
87 + public void packetReactiveProcessor(IpAddress dstIpAddress, IpAddress srcIpAddress,
88 + ConnectPoint srcConnectPoint, MacAddress srcMacAddress) {
89 +
90 + }
91 +
92 + @Override
93 + public FibListener getFibListener() {
94 + return fibListener;
95 + }
96 +
97 +}
...@@ -25,5 +25,11 @@ ...@@ -25,5 +25,11 @@
25 <command> 25 <command>
26 <action class="org.onosproject.routing.cli.RoutesListCommand"/> 26 <action class="org.onosproject.routing.cli.RoutesListCommand"/>
27 </command> 27 </command>
28 + <command>
29 + <action class="org.onosproject.routing.cli.AddRouteCommand"/>
30 + </command>
31 + <command>
32 + <action class="org.onosproject.routing.cli.RemoveRouteCommand"/>
33 + </command>
28 </command-bundle> 34 </command-bundle>
29 </blueprint> 35 </blueprint>
......