1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.api.BenkoBox;
6 /** anything that has a destination address on the switch fabric */
7 public abstract class InterpreterBenkoBox extends BenkoBox {
9 private final String name;
10 private final InterpreterShip ship;
11 private final Destination[] ports;
12 private final int addr = max_addr++;
14 public InterpreterBenkoBox(InterpreterShip ship, String name, String[] ports) {
17 this.ports = new Destination[ports.length];
18 for(int i=0; i<ports.length; i++)
20 new InterpreterBenkoBoxDestination(ports[i]);
23 public Iterable<Destination> getDestinations() {
24 HashSet<Destination> ret = new HashSet<Destination>();
25 for(Destination d : ports) ret.add(d);
29 /** adds the included datum to the port from the switch fabric side */
30 public abstract void addDataFromFabric(Packet packet);
32 abstract void service();
34 abstract void shutdown();
36 public Ship getShip() { return ship; }
37 public Fleet getFleet() { return getShip().getFleet(); }
38 public String toString() { return ship+"."+name; }
39 public String getName() { return name; }
40 public int getInstructionFifoLength() { return 4; }
42 Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
44 public long getDestAddr() { return addr; }
46 private static int max_addr;
48 private class InterpreterBenkoBoxDestination extends InterpreterDestination {
50 public long addr = max_addr++;
51 public InterpreterBenkoBoxDestination(String name) { this.name = name; }
52 public String getDestinationName() { return name; }
53 public Ship getShip() { return InterpreterBenkoBox.this.getShip(); }
54 public void addDataFromFabric(Packet packet) { InterpreterBenkoBox.this.addDataFromFabric(packet); }
55 public String toString() { return getShip()+"."+getName(); }
56 public long getDestAddr() { return addr; }